/[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 63 by dpavlin, Sat Oct 13 15:05:59 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_openpic.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    
86    DEVICE_ACCESS(openpic)
87  {  {
88          struct gc_data *d = extra;          struct openpic_data *d = extra;
89          uint64_t idata = 0, odata = 0;          uint64_t idata = 0, odata = 0;
90    
91          if (writeflag == MEM_WRITE)          if (writeflag == MEM_WRITE)
# Line 71  DEVICE_ACCESS(gc) Line 113  DEVICE_ACCESS(gc)
113                  if (writeflag == MEM_READ)                  if (writeflag == MEM_READ)
114                          odata = d->enable_hi;                          odata = d->enable_hi;
115                  else {                  else {
116                          uint32_t old_enable_hi = d->enable_hi;                          int old_assert = (d->status_lo & d->enable_lo
117                                || d->status_hi & d->enable_hi);
118                            int new_assert;
119                          d->enable_hi = idata;                          d->enable_hi = idata;
120                          if (d->enable_hi != old_enable_hi)  
121                                  cpu_interrupt(cpu, d->reassert_irq);                          new_assert = (d->status_lo & d->enable_lo ||
122                                d->status_hi & d->enable_hi);
123    
124                            if (old_assert && !new_assert)
125                                    INTERRUPT_DEASSERT(d->cpu_irq);
126                            else if (!old_assert && new_assert)
127                                    INTERRUPT_ASSERT(d->cpu_irq);
128                  }                  }
129                  break;                  break;
130    
131          case 0x18:          case 0x18:
132                  if (writeflag == MEM_WRITE) {                  if (writeflag == MEM_WRITE) {
133                          uint32_t old_status_hi = d->status_hi;                          int old_assert = (d->status_lo & d->enable_lo
134                                || d->status_hi & d->enable_hi);
135                            int new_assert;
136                          d->status_hi &= ~idata;                          d->status_hi &= ~idata;
137                          if (d->status_hi != old_status_hi)  
138                                  cpu_interrupt(cpu, d->reassert_irq);                          new_assert = (d->status_lo & d->enable_lo ||
139                                d->status_hi & d->enable_hi);
140    
141                            if (old_assert && !new_assert)
142                                    INTERRUPT_DEASSERT(d->cpu_irq);
143                            else if (!old_assert && new_assert)
144                                    INTERRUPT_ASSERT(d->cpu_irq);
145                  }                  }
146                  break;                  break;
147    
# Line 96  DEVICE_ACCESS(gc) Line 154  DEVICE_ACCESS(gc)
154                  if (writeflag == MEM_READ)                  if (writeflag == MEM_READ)
155                          odata = d->enable_lo;                          odata = d->enable_lo;
156                  else {                  else {
157                          uint32_t old_enable_lo = d->enable_lo;                          int old_assert = (d->status_lo & d->enable_lo
158                                || d->status_hi & d->enable_hi);
159                            int new_assert;
160                          d->enable_lo = idata;                          d->enable_lo = idata;
161                          if (d->enable_lo != old_enable_lo)  
162                                  cpu_interrupt(cpu, d->reassert_irq);                          new_assert = (d->status_lo & d->enable_lo ||
163                                d->status_hi & d->enable_hi);
164    
165                            if (old_assert && !new_assert)
166                                    INTERRUPT_DEASSERT(d->cpu_irq);
167                            else if (!old_assert && new_assert)
168                                    INTERRUPT_ASSERT(d->cpu_irq);
169                  }                  }
170                  break;                  break;
171    
172          case 0x28:          case 0x28:
173                  if (writeflag == MEM_WRITE) {                  if (writeflag == MEM_WRITE) {
174                          uint32_t old_status_lo = d->status_lo;                          int old_assert = (d->status_lo & d->enable_lo
175                                || d->status_hi & d->enable_hi);
176                            int new_assert;
177                          d->status_lo &= ~idata;                          d->status_lo &= ~idata;
178                          if (d->status_lo != old_status_lo)  
179                                  cpu_interrupt(cpu, d->reassert_irq);                          new_assert = (d->status_lo & d->enable_lo ||
180                                d->status_hi & d->enable_hi);
181    
182                            if (old_assert && !new_assert)
183                                    INTERRUPT_DEASSERT(d->cpu_irq);
184                            else if (!old_assert && new_assert)
185                                    INTERRUPT_ASSERT(d->cpu_irq);
186                  }                  }
187                  break;                  break;
188    
189            case 0x1c:
190          case 0x2c:          case 0x2c:
191                  /*  Avoir a debug message.  */                  /*  Avoid a debug message.  */
192                  break;                  break;
193    
194          default:if (writeflag == MEM_WRITE) {          default:if (writeflag == MEM_WRITE) {
195                          fatal("[ gc: unimplemented write to "                          fatal("[ openpic: unimplemented write to "
196                              "offset 0x%x: data=0x%x ]\n", (int)                              "offset 0x%x: data=0x%x ]\n", (int)
197                              relative_addr, (int)idata);                              relative_addr, (int)idata);
198                  } else {                  } else {
199                          fatal("[ gc: unimplemented read from "                          fatal("[ openpic: unimplemented read from "
200                              "offset 0x%x ]\n", (int)relative_addr);                              "offset 0x%x ]\n", (int)relative_addr);
201                  }                  }
202          }          }
# Line 133  DEVICE_ACCESS(gc) Line 208  DEVICE_ACCESS(gc)
208  }  }
209    
210    
211  /*  DEVINIT(openpic)
  *  dev_gc_init():  
  */  
 struct gc_data *dev_gc_init(struct machine *machine, struct memory *mem,  
         uint64_t addr, int reassert_irq)  
212  {  {
213          struct gc_data *d;          struct openpic_data *d;
214            int i;
215    
216          d = malloc(sizeof(struct gc_data));          CHECK_ALLOCATION(d = malloc(sizeof(struct openpic_data)));
217          if (d == NULL) {          memset(d, 0, sizeof(struct openpic_data));
218                  fprintf(stderr, "out of memory\n");  
219                  exit(1);          /*  Connect to the CPU interrupt pin:  */
220            INTERRUPT_CONNECT(devinit->interrupt_path, d->cpu_irq);
221    
222            /*
223             *  Register the 64 Grand Central interrupts (32 lo, 32 hi):
224             */
225            for (i=0; i<32; i++) {
226                    struct interrupt template;
227                    char n[300];
228                    snprintf(n, sizeof(n), "%s.openpic.lo.%i",
229                        devinit->interrupt_path, i);
230                    memset(&template, 0, sizeof(template));
231                    template.line = 1 << i;
232                    template.name = n;
233                    template.extra = d;
234                    template.interrupt_assert = openpic_lo_interrupt_assert;
235                    template.interrupt_deassert = openpic_lo_interrupt_deassert;
236                    interrupt_handler_register(&template);
237    
238                    snprintf(n, sizeof(n), "%s.openpic.hi.%i",
239                        devinit->interrupt_path, i);
240                    memset(&template, 0, sizeof(template));
241                    template.line = 1 << i;
242                    template.name = n;
243                    template.extra = d;
244                    template.interrupt_assert = openpic_hi_interrupt_assert;
245                    template.interrupt_deassert = openpic_hi_interrupt_deassert;
246                    interrupt_handler_register(&template);
247          }          }
         memset(d, 0, sizeof(struct gc_data));  
         d->reassert_irq = reassert_irq;  
248    
249          memory_device_register(mem, "gc", addr, 0x100,          memory_device_register(devinit->machine->memory, "openpic",
250              dev_gc_access, d, DM_DEFAULT, NULL);              devinit->addr, DEV_OPENPIC_LENGTH, dev_openpic_access, d, DM_DEFAULT, NULL);
251    
252          return d;          return 1;
253  }  }
254    

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

  ViewVC Help
Powered by ViewVC 1.1.26