/[gxemul]/trunk/src/devices/dev_openpic.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/src/devices/dev_openpic.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/src/devices/dev_gc.c revision 24 by dpavlin, Mon Oct 8 16:19:56 2007 UTC trunk/src/devices/dev_openpic.c revision 67 by dpavlin, Sun Oct 14 13:46:39 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2005-2006  Anders Gavare.  All rights reserved.   *  Copyright (C) 2005-2007  Anders Gavare.  All rights reserved.
3   *   *
4   *  Redistribution and use in source and binary forms, with or without   *  Redistribution and use in source and binary forms, with or without
5   *  modification, are permitted provided that the following conditions are met:   *  modification, are permitted provided that the following conditions are met:
# Line 24  Line 24 
24   *  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF   *  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *     *  
27   *  $Id: dev_gc.c,v 1.8 2006/02/27 05:32:26 debug Exp $   *  $Id: dev_openpic.c,v 1.14 2007/09/11 21:42:52 debug Exp $
28   *     *  
29   *  Grand Central Interrupt controller (used by MacPPC).   *  COMMENT: OpenPIC Interrupt controller (used by sandpoint ppc)
30     *  based on dev_gc.c
31   */   */
32    
33  #include <stdio.h>  #include <stdio.h>
# Line 35  Line 36 
36    
37  #include "cpu.h"  #include "cpu.h"
38  #include "device.h"  #include "device.h"
 #include "devices.h"  
39  #include "machine.h"  #include "machine.h"
40  #include "memory.h"  #include "memory.h"
41  #include "misc.h"  #include "misc.h"
42    
43    
44  DEVICE_ACCESS(gc)  #define DEV_OPENPIC_LENGTH              0x40000
45    
46    struct openpic_data {
47            struct interrupt cpu_irq;
48    
49            uint32_t        status_hi;
50            uint32_t        status_lo;
51            uint32_t        enable_hi;
52            uint32_t        enable_lo;
53    };
54    
55    
56    void openpic_hi_interrupt_assert(struct interrupt *interrupt)
57    {
58            struct openpic_data *d = interrupt->extra;
59            d->status_hi |= interrupt->line;
60            if (d->status_lo & d->enable_lo || d->status_hi & d->enable_hi)
61                    INTERRUPT_ASSERT(d->cpu_irq);
62    }
63    void openpic_hi_interrupt_deassert(struct interrupt *interrupt)
64    {
65            struct openpic_data *d = interrupt->extra;
66            d->status_hi &= ~interrupt->line;
67            if (!(d->status_lo & d->enable_lo || d->status_hi & d->enable_hi))
68                    INTERRUPT_DEASSERT(d->cpu_irq);
69    }
70    void openpic_lo_interrupt_assert(struct interrupt *interrupt)
71    {
72            struct openpic_data *d = interrupt->extra;
73            d->status_lo |= interrupt->line;
74            if (d->status_lo & d->enable_lo || d->status_hi & d->enable_hi)
75                    INTERRUPT_ASSERT(d->cpu_irq);
76    }
77    void openpic_lo_interrupt_deassert(struct interrupt *interrupt)
78    {
79            struct openpic_data *d = interrupt->extra;
80            d->status_lo &= ~interrupt->line;
81            if (!(d->status_lo & d->enable_lo || d->status_hi & d->enable_hi))
82                    INTERRUPT_DEASSERT(d->cpu_irq);
83    }
84    
85    #define OPENPIC_MASK                            0x80000000
86    #define OPENPIC_ACTIVITY                        0x40000000      /* Read Only */
87    #define OPENPIC_PRIORITY_MASK                   0x000f0000
88    #define OPENPIC_PRIORITY_SHIFT                  16
89    #define OPENPIC_VECTOR_MASK                     0x000000ff
90    
91    #define OPENPIC_VEC_TIMER       64      /* and up */
92    #define OPENPIC_VEC_IPI         72      /* and up */
93    #define OPENPIC_VEC_SPURIOUS    127
94    
95    #define OPENPIC_NUM_TIMERS      4
96    #define OPENPIC_NUM_IPI         4
97    #define OPENPIC_NUM_PRI         16
98    #define OPENPIC_NUM_VECTORS     256
99    
100    DEVICE_ACCESS(openpic)
101  {  {
102          struct gc_data *d = extra;  //      struct openpic_data *d = extra;
103          uint64_t idata = 0, odata = 0;          uint64_t idata = 0, odata = 0, decoded = 0;
104    
105          if (writeflag == MEM_WRITE)          if (writeflag == MEM_WRITE) {
106                  idata = memory_readmax64(cpu, data, len);                  idata = memory_readmax64(cpu, data, len);
107                    decoded =
108                            ( idata & 0x000000ff ) << 24 |
109                            ( idata & 0x0000ff00 ) << 8  |
110                            ( idata & 0x00ff0000 ) >> 8  |
111                            ( idata & 0xff000000 ) >> 24 ;
112    
113                    uint64_t priority,vector, active;
114                    priority = ( decoded & OPENPIC_PRIORITY_MASK ) >> OPENPIC_PRIORITY_SHIFT;
115                    vector   = ( decoded & OPENPIC_VECTOR_MASK );
116                    active   = ( decoded & OPENPIC_ACTIVITY );
117    
118                    debug("[ openpic: WRITE %05x | %08x => %08x | priority: %x vector: 0x%02x %d active: %x ]\n",
119                            (int)relative_addr, (int)idata, (int)decoded, (int)priority, (int)vector, (int)vector, (int)active );
120            }
121    
122          switch (relative_addr) {          switch (relative_addr) {
123    
124            case 0x00:
125                    if (writeflag == MEM_READ) {
126                            // version 1.2
127                            odata = 0x02000000;
128                            fatal("[ openpic: read from "
129                                "offset 0x%x (OpenPIC version) = %x]\n", (int)
130                                relative_addr, (int)odata);
131                    }
132                    fatal("[ openpic: unimplemented write to "
133                        "offset 0x%x: data=0x%x (OpenPIC version) ]\n", (int)
134                        relative_addr, (int)idata);
135                    break;
136    
137  #if 0  #if 0
138  #define INT_STATE_REG_H  (interrupt_reg + 0x00)  #define INT_STATE_REG_H  (interrupt_reg + 0x00)
139  #define INT_ENABLE_REG_H (interrupt_reg + 0x04)  #define INT_ENABLE_REG_H (interrupt_reg + 0x04)
# Line 60  DEVICE_ACCESS(gc) Line 143  DEVICE_ACCESS(gc)
143  #define INT_ENABLE_REG_L (interrupt_reg + 0x14)  #define INT_ENABLE_REG_L (interrupt_reg + 0x14)
144  #define INT_CLEAR_REG_L  (interrupt_reg + 0x18)  #define INT_CLEAR_REG_L  (interrupt_reg + 0x18)
145  #define INT_LEVEL_REG_L  (interrupt_reg + 0x1c)  #define INT_LEVEL_REG_L  (interrupt_reg + 0x1c)
 #endif  
146    
147          case 0x10:          case 0x10:
148                  if (writeflag == MEM_READ)                  if (writeflag == MEM_READ)
# Line 71  DEVICE_ACCESS(gc) Line 153  DEVICE_ACCESS(gc)
153                  if (writeflag == MEM_READ)                  if (writeflag == MEM_READ)
154                          odata = d->enable_hi;                          odata = d->enable_hi;
155                  else {                  else {
156                          uint32_t old_enable_hi = d->enable_hi;                          int old_assert = (d->status_lo & d->enable_lo
157                                || d->status_hi & d->enable_hi);
158                            int new_assert;
159                          d->enable_hi = idata;                          d->enable_hi = idata;
160                          if (d->enable_hi != old_enable_hi)  
161                                  cpu_interrupt(cpu, d->reassert_irq);                          new_assert = (d->status_lo & d->enable_lo ||
162                                d->status_hi & d->enable_hi);
163    
164                            if (old_assert && !new_assert)
165                                    INTERRUPT_DEASSERT(d->cpu_irq);
166                            else if (!old_assert && new_assert)
167                                    INTERRUPT_ASSERT(d->cpu_irq);
168                  }                  }
169                  break;                  break;
170    
171          case 0x18:          case 0x18:
172                  if (writeflag == MEM_WRITE) {                  if (writeflag == MEM_WRITE) {
173                          uint32_t old_status_hi = d->status_hi;                          int old_assert = (d->status_lo & d->enable_lo
174                                || d->status_hi & d->enable_hi);
175                            int new_assert;
176                          d->status_hi &= ~idata;                          d->status_hi &= ~idata;
177                          if (d->status_hi != old_status_hi)  
178                                  cpu_interrupt(cpu, d->reassert_irq);                          new_assert = (d->status_lo & d->enable_lo ||
179                                d->status_hi & d->enable_hi);
180    
181                            if (old_assert && !new_assert)
182                                    INTERRUPT_DEASSERT(d->cpu_irq);
183                            else if (!old_assert && new_assert)
184                                    INTERRUPT_ASSERT(d->cpu_irq);
185                  }                  }
186                  break;                  break;
187    
# Line 96  DEVICE_ACCESS(gc) Line 194  DEVICE_ACCESS(gc)
194                  if (writeflag == MEM_READ)                  if (writeflag == MEM_READ)
195                          odata = d->enable_lo;                          odata = d->enable_lo;
196                  else {                  else {
197                          uint32_t old_enable_lo = d->enable_lo;                          int old_assert = (d->status_lo & d->enable_lo
198                                || d->status_hi & d->enable_hi);
199                            int new_assert;
200                          d->enable_lo = idata;                          d->enable_lo = idata;
201                          if (d->enable_lo != old_enable_lo)  
202                                  cpu_interrupt(cpu, d->reassert_irq);                          new_assert = (d->status_lo & d->enable_lo ||
203                                d->status_hi & d->enable_hi);
204    
205                            if (old_assert && !new_assert)
206                                    INTERRUPT_DEASSERT(d->cpu_irq);
207                            else if (!old_assert && new_assert)
208                                    INTERRUPT_ASSERT(d->cpu_irq);
209                  }                  }
210                  break;                  break;
211    
212          case 0x28:          case 0x28:
213                  if (writeflag == MEM_WRITE) {                  if (writeflag == MEM_WRITE) {
214                          uint32_t old_status_lo = d->status_lo;                          int old_assert = (d->status_lo & d->enable_lo
215                                || d->status_hi & d->enable_hi);
216                            int new_assert;
217                          d->status_lo &= ~idata;                          d->status_lo &= ~idata;
218                          if (d->status_lo != old_status_lo)  
219                                  cpu_interrupt(cpu, d->reassert_irq);                          new_assert = (d->status_lo & d->enable_lo ||
220                                d->status_hi & d->enable_hi);
221    
222                            if (old_assert && !new_assert)
223                                    INTERRUPT_DEASSERT(d->cpu_irq);
224                            else if (!old_assert && new_assert)
225                                    INTERRUPT_ASSERT(d->cpu_irq);
226                  }                  }
227                  break;                  break;
228    
229            case 0x1c:
230          case 0x2c:          case 0x2c:
231                  /*  Avoir a debug message.  */                  /*  Avoid a debug message.  */
232                  break;                  break;
233    #endif
234          default:if (writeflag == MEM_WRITE) {          default:if (writeflag == MEM_WRITE) {
235                          fatal("[ gc: unimplemented write to "                          fatal("[ openpic: unimplemented write to "
236                              "offset 0x%x: data=0x%x ]\n", (int)                              "offset 0x%x: data=0x%x ]\n", (int)
237                              relative_addr, (int)idata);                              relative_addr, (int)idata);
238                  } else {                  } else {
239                          fatal("[ gc: unimplemented read from "                          fatal("[ openpic: unimplemented read from "
240                              "offset 0x%x ]\n", (int)relative_addr);                              "offset 0x%x ]\n", (int)relative_addr);
241                  }                  }
242          }          }
# Line 133  DEVICE_ACCESS(gc) Line 248  DEVICE_ACCESS(gc)
248  }  }
249    
250    
251  /*  DEVINIT(openpic)
  *  dev_gc_init():  
  */  
 struct gc_data *dev_gc_init(struct machine *machine, struct memory *mem,  
         uint64_t addr, int reassert_irq)  
252  {  {
253          struct gc_data *d;          struct openpic_data *d;
254            int i;
255    
256            CHECK_ALLOCATION(d = malloc(sizeof(struct openpic_data)));
257            memset(d, 0, sizeof(struct openpic_data));
258    
259          d = malloc(sizeof(struct gc_data));          /*  Connect to the CPU interrupt pin:  */
260          if (d == NULL) {          INTERRUPT_CONNECT(devinit->interrupt_path, d->cpu_irq);
261                  fprintf(stderr, "out of memory\n");  
262                  exit(1);          /*
263             *  Register the 126 OpenPIC interrupts
264             */
265            for (i=0; i<126; i++) {
266                    struct interrupt template;
267                    char n[300];
268                    snprintf(n, sizeof(n), "%s.openpic.%i",
269                        devinit->interrupt_path, i);
270                    memset(&template, 0, sizeof(template));
271                    template.line = 1 << i;
272                    template.name = n;
273                    template.extra = d;
274                    template.interrupt_assert = openpic_lo_interrupt_assert;
275                    template.interrupt_deassert = openpic_lo_interrupt_deassert;
276                    interrupt_handler_register(&template);
277          }          }
         memset(d, 0, sizeof(struct gc_data));  
         d->reassert_irq = reassert_irq;  
278    
279          memory_device_register(mem, "gc", addr, 0x100,          memory_device_register(devinit->machine->memory, "openpic",
280              dev_gc_access, d, DM_DEFAULT, NULL);              devinit->addr, DEV_OPENPIC_LENGTH, dev_openpic_access, d, DM_DEFAULT, NULL);
281    
282          return d;          return 1;
283  }  }
284    

Legend:
Removed from v.24  
changed lines
  Added in v.67

  ViewVC Help
Powered by ViewVC 1.1.26