/[gxemul]/trunk/src/devices/dev_mpc10x.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_mpc10x.c

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

trunk/src/devices/dev_cpc700.c revision 22 by dpavlin, Mon Oct 8 16:19:37 2007 UTC trunk/src/devices/dev_mpc10x.c revision 57 by dpavlin, Thu Oct 11 18:57:32 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 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *     *  
27   *   *
28   *  $Id: dev_cpc700.c,v 1.7 2006/01/01 13:17:16 debug Exp $   *  $Id: dev_mpc10x.c,v 1.12 2007/06/15 18:13:04 debug Exp $
29   *     *
30   *  IBM CPC700 bridge; PCI and interrupt controller.   *  COMMENT: IBM mpc10x bridge (PCI and interrupt controller)
31   */   */
32    
33  #include <stdio.h>  #include <stdio.h>
# Line 37  Line 37 
37  #include "bus_pci.h"  #include "bus_pci.h"
38  #include "cpu.h"  #include "cpu.h"
39  #include "device.h"  #include "device.h"
40  #include "devices.h"  #include "interrupt.h"
41  #include "machine.h"  #include "machine.h"
42  #include "memory.h"  #include "memory.h"
43  #include "misc.h"  #include "misc.h"
44    
45  #include "cpc700reg.h"  #include "mpc10xreg.h"
46    
47    
48    struct mpc10x_data {
49            struct interrupt ppc_irq;       /*  Connected to the CPU  */
50    
51            uint32_t        sr;             /*  Interrupt Status register  */
52            uint32_t        er;             /*  Interrupt Enable register  */
53    
54            struct pci_data *pci_data;      /*  PCI bus  */
55    };
56    
57    
58    void mpc10x_interrupt_assert(struct interrupt *interrupt)
59    {
60            struct mpc10x_data *d = interrupt->extra;
61            d->sr |= interrupt->line;
62            if (d->sr & d->er)
63                    INTERRUPT_ASSERT(d->ppc_irq);
64    }
65    void mpc10x_interrupt_deassert(struct interrupt *interrupt)
66    {
67            struct mpc10x_data *d = interrupt->extra;
68            d->sr &= ~interrupt->line;
69            if (!(d->sr & d->er))
70                    INTERRUPT_DEASSERT(d->ppc_irq);
71    }
72    
73    
74  /*  /*
75   *  dev_cpc700_pci_access():   *  dev_mpc10x_pci_access():
76   *   *
77   *  Passes PCI indirect addr and data accesses onto bus_pci.   *  Passes PCI indirect addr and data accesses onto bus_pci.
78   */   */
79  DEVICE_ACCESS(cpc700_pci)  DEVICE_ACCESS(mpc10x_pci)
80  {  {
81          uint64_t idata = 0, odata = 0;          uint64_t idata = 0, odata = 0;
82          int bus, dev, func, reg;          int bus, dev, func, reg;
83          struct cpc700_data *d = extra;          struct mpc10x_data *d = extra;
84    
85          if (writeflag == MEM_WRITE)          if (writeflag == MEM_WRITE) {
86                  idata = memory_readmax64(cpu, data, len|MEM_PCI_LITTLE_ENDIAN);                  idata = memory_readmax64(cpu, data, len|MEM_PCI_LITTLE_ENDIAN);
87                    debug("mpc10x_pci WRITE offset 0x%x: 0x%x\n", relative_addr, odata);
88            }
89    
90            debug("relative: %d i: 0x%x o: 0x%x data: %s len: %d\n", relative_addr,idata, odata, data, len );
91    
92          switch (relative_addr) {          switch (relative_addr) {
93          case 0: /*  Address:  */          case 0: /*  Address:  */
# Line 71  DEVICE_ACCESS(cpc700_pci) Line 101  DEVICE_ACCESS(cpc700_pci)
101                  break;                  break;
102          }          }
103    
104          if (writeflag == MEM_READ)  #define PCI_VENDOR_ID_MOTOROLA          0x1057
105    #define MPC10X_BRIDGE_106       ((PCI_DEVICE_ID_MOTOROLA_MPC106 << 16) |  \
106                                      PCI_VENDOR_ID_MOTOROLA)
107    #define MPC10X_BRIDGE_8240      ((0x0003 << 16) | PCI_VENDOR_ID_MOTOROLA)
108    #define MPC10X_BRIDGE_107       ((0x0004 << 16) | PCI_VENDOR_ID_MOTOROLA)
109    #define MPC10X_BRIDGE_8245      ((0x0006 << 16) | PCI_VENDOR_ID_MOTOROLA)
110    
111            debug("i: 0x%x o: 0x%x\n", idata, odata );
112            if (writeflag == MEM_READ) {
113                  memory_writemax64(cpu, data, len|MEM_PCI_LITTLE_ENDIAN, odata);                  memory_writemax64(cpu, data, len|MEM_PCI_LITTLE_ENDIAN, odata);
114                    odata = MPC10X_BRIDGE_8245;
115                    debug("mpc10x_pci READ offset 0x%x: 0x%x\n", relative_addr, odata);
116            }
117    
118          return 1;          return 1;
119  }  }
120    
121    
122  /*  /*
123   *  dev_cpc700_int_access():   *  dev_mpc10x_int_access():
124   *   *
125   *  The interrupt controller.   *  The interrupt controller.
126   */   */
127  DEVICE_ACCESS(cpc700_int)  DEVICE_ACCESS(mpc10x_int)
128  {  {
129          struct cpc700_data *d = extra;          struct mpc10x_data *d = extra;
130          uint64_t idata = 0, odata = 0;          uint64_t idata = 0, odata = 0;
131    
132          if (writeflag == MEM_WRITE)          if (writeflag == MEM_WRITE)
# Line 93  DEVICE_ACCESS(cpc700_int) Line 134  DEVICE_ACCESS(cpc700_int)
134    
135          switch (relative_addr) {          switch (relative_addr) {
136    
137          case CPC_UIC_SR:          case MPC_UIC_SR:
138                  /*  Status register (cleared by writing ones):  */                  /*  Status register (cleared by writing ones):  */
139                  if (writeflag == MEM_READ)                  if (writeflag == MEM_READ) {
140                          odata = d->sr;                          odata = d->sr;
141                  else                  } else {
142                          d->sr &= ~idata;                          d->sr &= ~idata;
143                            if (!(d->sr & d->er))
144                                    INTERRUPT_DEASSERT(d->ppc_irq);
145                    }
146                  break;                  break;
147    
148          case CPC_UIC_SRS:          case MPC_UIC_SRS:
149                  /*  Status register set:  */                  /*  Status register set:  */
150                  if (writeflag == MEM_READ) {                  if (writeflag == MEM_READ) {
151                          fatal("[ cpc700_int: read from CPC_UIC_SRS? ]\n");                          fatal("[ mpc10x_int: read from MPC_UIC_SRS? ]\n");
152                          odata = d->sr;                          odata = d->sr;
153                  } else                  } else {
154                          d->sr = idata;                          d->sr = idata;
155                            if (d->sr & d->er)
156                                    INTERRUPT_ASSERT(d->ppc_irq);
157                            else
158                                    INTERRUPT_DEASSERT(d->ppc_irq);
159                    }
160                  break;                  break;
161    
162          case CPC_UIC_ER:          case MPC_UIC_ER:
163                  /*  Enable register:  */                  /*  Enable register:  */
164                  if (writeflag == MEM_READ)                  if (writeflag == MEM_READ) {
165                          odata = d->er;                          odata = d->er;
166                  else                  } else {
167                          d->er = idata;                          d->er = idata;
168                            if (d->sr & d->er)
169                                    INTERRUPT_ASSERT(d->ppc_irq);
170                            else
171                                    INTERRUPT_DEASSERT(d->ppc_irq);
172                    }
173                  break;                  break;
174    
175          case CPC_UIC_MSR:          case MPC_UIC_MSR:
176                  /*  Masked status:  */                  /*  Masked status:  */
177                  if (writeflag == MEM_READ)                  if (writeflag == MEM_READ) {
178                          odata = d->sr & d->er;                          odata = d->sr & d->er;
179                  else                  } else {
180                          fatal("[ cpc700_int: write to CPC_UIC_MSR? ]\n");                          fatal("[ mpc10x_int: write to MPC_UIC_MSR? ]\n");
181                    }
182                  break;                  break;
183    
184          default:if (writeflag == MEM_WRITE) {          default:if (writeflag == MEM_WRITE) {
185                          fatal("[ cpc700_int: unimplemented write to "                          fatal("[ mpc10x_int: unimplemented write to "
186                              "offset 0x%x: data=0x%x ]\n", (int)                              "offset 0x%x: data=0x%x ]\n", (int)
187                              relative_addr, (int)idata);                              relative_addr, (int)idata);
188                  } else {                  } else {
189                          fatal("[ cpc700_int: unimplemented read from "                          fatal("[ mpc10x_int: unimplemented read from "
190                              "offset 0x%x ]\n", (int)relative_addr);                              "offset 0x%x ]\n", (int)relative_addr);
191                  }                  }
192          }          }
# Line 142  DEVICE_ACCESS(cpc700_int) Line 197  DEVICE_ACCESS(cpc700_int)
197          return 1;          return 1;
198  }  }
199    
   
200  /*  /*
201   *  dev_cpc700_init():   *  dev_mpc10x_config_access():
202     *
203     *  Configuration
204   */   */
205  struct cpc700_data *dev_cpc700_init(struct machine *machine, struct memory *mem)  DEVICE_ACCESS(mpc10x_config)
206    {
207            uint64_t idata = 0, odata = 0;
208    //      struct mpc10x_data *d = extra;
209    
210            if (writeflag == MEM_WRITE) {
211                    idata = memory_readmax64(cpu, data, len);
212                    debug("mpc10x_config WRITE offset 0x%x: 0x%x [old: 0x%x]\n", relative_addr, odata, idata);
213            }
214    
215            debug("relative: %d i: 0x%x o: 0x%x data: %s len: %d\n", relative_addr,idata, odata, data, len );
216    
217            switch (relative_addr) {
218            case 0:
219    
220    #define PCI_VENDOR_ID_MOTOROLA          0x1057
221    #define MPC10X_BRIDGE_106       ((PCI_DEVICE_ID_MOTOROLA_MPC106 << 16) |  \
222                                      PCI_VENDOR_ID_MOTOROLA)
223    #define MPC10X_BRIDGE_8240      ((0x0003 << 16) | PCI_VENDOR_ID_MOTOROLA)
224    #define MPC10X_BRIDGE_107       ((0x0004 << 16) | PCI_VENDOR_ID_MOTOROLA)
225    #define MPC10X_BRIDGE_8245      ((0x0006 << 16) | PCI_VENDOR_ID_MOTOROLA)
226    
227                    return MPC10X_BRIDGE_8245;
228            }
229    
230            debug("i: 0x%x o: 0x%x\n", idata, odata );
231            if (writeflag == MEM_READ) {
232                    odata = MPC10X_BRIDGE_8245;
233                    memory_writemax64(cpu, data, len, odata);
234                    debug("mpc10x_config READ offset 0x%x: 0x%x\n", relative_addr, odata);
235            }
236    
237            return 1;
238    }
239    
240    DEVINIT(mpc10x)
241  {  {
242          struct cpc700_data *d;          struct mpc10x_data *d;
243          char tmp[300];          char tmp[300];
244            int i;
245    
246            CHECK_ALLOCATION(d = malloc(sizeof(struct mpc10x_data)));
247            memset(d, 0, sizeof(struct mpc10x_data));
248    
249            /*  Connect to the CPU's interrupt pin:  */
250            INTERRUPT_CONNECT(devinit->interrupt_path, d->ppc_irq);
251    
252          d = malloc(sizeof(struct cpc700_data));          /*  Register 32 mpc10x interrupts:  */
253          if (d == NULL) {          for (i=0; i<32; i++) {
254                  fprintf(stderr, "out of memory\n");                  struct interrupt template;
255                  exit(1);                  char n[300];
256                    snprintf(n, sizeof(n), "%s.mpc10x.%i",
257                        devinit->interrupt_path, i);
258                    memset(&template, 0, sizeof(template));
259                    template.line = 1 << i;
260                    template.name = n;
261                    template.extra = d;
262                    template.interrupt_assert = mpc10x_interrupt_assert;
263                    template.interrupt_deassert = mpc10x_interrupt_deassert;
264                    interrupt_handler_register(&template);
265          }          }
         memset(d, 0, sizeof(struct cpc700_data));  
266    
267          /*  Register a PCI bus:  */          /*  Register a PCI bus:  */
268            snprintf(tmp, sizeof(tmp), "%s.mpc10x", devinit->interrupt_path);
269          d->pci_data = bus_pci_init(          d->pci_data = bus_pci_init(
270              machine,              devinit->machine,
271              0                   /*  pciirq: TODO  */,              tmp,                /*  pciirq path  */
272              0,                  /*  pci device io offset  */              0xfc000000,         /*  pci device io offset  */
273              0,                  /*  pci device mem offset  */              0xfcc00000,         /*  pci device mem offset  */
274              CPC_PCI_IO_BASE,    /*  PCI portbase  */              0xfec00000,         /*  PCI portbase  */
275              CPC_PCI_MEM_BASE,   /*  PCI membase: TODO  */              0x80000000,         /*  PCI membase: TODO  */
276              0,                  /*  PCI irqbase: TODO  */              tmp,                /*  PCI irqbase  */
277              0,                  /*  ISA portbase: TODO  */              0,                  /*  ISA portbase: TODO  */
278              0,                  /*  ISA membase: TODO  */              0,                  /*  ISA membase: TODO  */
279              0);                 /*  ISA irqbase: TODO  */              tmp);               /*  ISA irqbase  */
280    
281          switch (machine->machine_type) {          /* PCI host bridge */
282          case MACHINE_PMPPC:          bus_pci_add(devinit->machine, d->pci_data,
283                  bus_pci_add(machine, d->pci_data, mem, 0, 0, 0,                  devinit->machine->memory, 0, 0, 0, "mpc10x_host_bridge");
284                      "heuricon_pmppc");  
285                  break;          /*  MPC10x configuration  */
286          default:fatal("!\n! WARNING: cpc700 for non-implemented machine"          memory_device_register(devinit->machine->memory, "mpc10x_config",
287                      " type\n!\n");              0xfec00000, 8, dev_mpc10x_config_access, d, DM_DEFAULT, NULL);
                 exit(1);  
         }  
288    
289          /*  PCI configuration registers:  */          /*  PCI configuration registers:  */
290          memory_device_register(mem, "cpc700_pci", CPC_PCICFGADR, 8,          memory_device_register(devinit->machine->memory, "mpc10x_pci",
291              dev_cpc700_pci_access, d, DM_DEFAULT, NULL);              0xfee00000, 8, dev_mpc10x_pci_access, d, DM_DEFAULT, NULL);
292    
293          /*  Interrupt controller:  */          /*  Interrupt controller:  */
294          memory_device_register(mem, "cpc700_int", CPC_UIC_BASE, CPC_UIC_SIZE,          memory_device_register(devinit->machine->memory, "mpc10x_int",
295              dev_cpc700_int_access, d, DM_DEFAULT, NULL);              MPC_UIC_BASE, MPC_UIC_SIZE, dev_mpc10x_int_access, d,
296                DM_DEFAULT, NULL);
297    
298          /*  Two serial ports:  */          /*  Two serial ports:  */
299          snprintf(tmp, sizeof(tmp), "ns16550 irq=%i addr=0x%llx name2=tty0",          snprintf(tmp, sizeof(tmp), "ns16550 irq=%s.mpc10x.%i addr=0x%llx "
300              31 - CPC_IB_UART_0, (long long)CPC_COM0);              "name2=tty0", devinit->interrupt_path, 31 - MPC_IB_UART_0,
301          machine->main_console_handle = (size_t)device_add(machine, tmp);              (long long)MPC_COM0);
302          snprintf(tmp, sizeof(tmp), "ns16550 irq=%i addr=0x%llx name2=tty1",          devinit->machine->main_console_handle = (size_t)
303              31 - CPC_IB_UART_1, (long long)CPC_COM1);              device_add(devinit->machine, tmp);
304          device_add(machine, tmp);  #if 0
305            snprintf(tmp, sizeof(tmp), "ns16550 irq=%s.mpc10x.%i addr=0x%llx "
306                "name2=tty1", devinit->interrupt_path, 31 - MPC_IB_UART_1,
307                (long long)MPC_COM1);
308            device_add(devinit->machine, tmp);
309    #endif
310    
311            devinit->return_ptr = d->pci_data;
312    
313          return d;          return 1;
314  }  }
315    

Legend:
Removed from v.22  
changed lines
  Added in v.57

  ViewVC Help
Powered by ViewVC 1.1.26