/[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 20 by dpavlin, Mon Oct 8 16:19:23 2007 UTC trunk/src/devices/dev_mpc10x.c revision 53 by dpavlin, Thu Oct 11 12:54:37 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2005  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.3 2005/11/22 02:07:39 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_access().   *  Passes PCI indirect addr and data accesses onto bus_pci.
78   */   */
79  int dev_cpc700_pci_access(struct cpu *cpu, struct memory *mem,  DEVICE_ACCESS(mpc10x_pci)
         uint64_t relative_addr, unsigned char *data, size_t len,  
         int writeflag, void *extra)  
80  {  {
81          uint64_t idata = 0, odata = 0;          uint64_t idata = 0, odata = 0;
82          struct cpc700_data *d = extra;          int bus, dev, func, reg;
83            struct mpc10x_data *d = extra;
84    
85          if (writeflag == MEM_WRITE)          if (writeflag == MEM_WRITE)
86                  idata = memory_readmax64(cpu, data, len);                  idata = memory_readmax64(cpu, data, len|MEM_PCI_LITTLE_ENDIAN);
87    
88          relative_addr += BUS_PCI_ADDR;          switch (relative_addr) {
89            case 0: /*  Address:  */
90                    bus_pci_decompose_1(idata, &bus, &dev, &func, &reg);
91                    bus_pci_setaddr(cpu, d->pci_data, bus, dev, func, reg);
92                    break;
93    
94          if (writeflag == MEM_WRITE)          case 4: /*  Data:  */
95                  bus_pci_access(cpu, mem, relative_addr, &idata,                  bus_pci_data_access(cpu, d->pci_data, writeflag == MEM_READ?
96                      len, writeflag, d->pci_data);                      &odata : &idata, len, writeflag);
97          else                  break;
98                  bus_pci_access(cpu, mem, relative_addr, &odata,          }
                     len, writeflag, d->pci_data);  
99    
100          if (writeflag == MEM_READ)          if (writeflag == MEM_READ)
101                  memory_writemax64(cpu, data, len, odata);                  memory_writemax64(cpu, data, len|MEM_PCI_LITTLE_ENDIAN, odata);
102    
103          return 1;          return 1;
104  }  }
105    
106    
107  /*  /*
108   *  dev_cpc700_int_access():   *  dev_mpc10x_int_access():
109   *   *
110   *  The interrupt controller.   *  The interrupt controller.
111   */   */
112  int dev_cpc700_int_access(struct cpu *cpu, struct memory *mem,  DEVICE_ACCESS(mpc10x_int)
         uint64_t relative_addr, unsigned char *data, size_t len,  
         int writeflag, void *extra)  
113  {  {
114          struct cpc700_data *d = extra;          struct mpc10x_data *d = extra;
115          uint64_t idata = 0, odata = 0;          uint64_t idata = 0, odata = 0;
116    
117          if (writeflag == MEM_WRITE)          if (writeflag == MEM_WRITE)
# Line 93  int dev_cpc700_int_access(struct cpu *cp Line 119  int dev_cpc700_int_access(struct cpu *cp
119    
120          switch (relative_addr) {          switch (relative_addr) {
121    
122          case CPC_UIC_SR:          case MPC_UIC_SR:
123                  /*  Status register (cleared by writing ones):  */                  /*  Status register (cleared by writing ones):  */
124                  if (writeflag == MEM_READ)                  if (writeflag == MEM_READ) {
125                          odata = d->sr;                          odata = d->sr;
126                  else                  } else {
127                          d->sr &= ~idata;                          d->sr &= ~idata;
128                            if (!(d->sr & d->er))
129                                    INTERRUPT_DEASSERT(d->ppc_irq);
130                    }
131                  break;                  break;
132    
133          case CPC_UIC_SRS:          case MPC_UIC_SRS:
134                  /*  Status register set:  */                  /*  Status register set:  */
135                  if (writeflag == MEM_READ) {                  if (writeflag == MEM_READ) {
136                          fatal("[ cpc700_int: read from CPC_UIC_SRS? ]\n");                          fatal("[ mpc10x_int: read from MPC_UIC_SRS? ]\n");
137                          odata = d->sr;                          odata = d->sr;
138                  } else                  } else {
139                          d->sr = idata;                          d->sr = idata;
140                            if (d->sr & d->er)
141                                    INTERRUPT_ASSERT(d->ppc_irq);
142                            else
143                                    INTERRUPT_DEASSERT(d->ppc_irq);
144                    }
145                  break;                  break;
146    
147          case CPC_UIC_ER:          case MPC_UIC_ER:
148                  /*  Enable register:  */                  /*  Enable register:  */
149                  if (writeflag == MEM_READ)                  if (writeflag == MEM_READ) {
150                          odata = d->er;                          odata = d->er;
151                  else                  } else {
152                          d->er = idata;                          d->er = idata;
153                            if (d->sr & d->er)
154                                    INTERRUPT_ASSERT(d->ppc_irq);
155                            else
156                                    INTERRUPT_DEASSERT(d->ppc_irq);
157                    }
158                  break;                  break;
159    
160          case CPC_UIC_MSR:          case MPC_UIC_MSR:
161                  /*  Masked status:  */                  /*  Masked status:  */
162                  if (writeflag == MEM_READ)                  if (writeflag == MEM_READ) {
163                          odata = d->sr & d->er;                          odata = d->sr & d->er;
164                  else                  } else {
165                          fatal("[ cpc700_int: write to CPC_UIC_MSR? ]\n");                          fatal("[ mpc10x_int: write to MPC_UIC_MSR? ]\n");
166                    }
167                  break;                  break;
168    
169          default:if (writeflag == MEM_WRITE) {          default:if (writeflag == MEM_WRITE) {
170                          fatal("[ cpc700_int: unimplemented write to "                          fatal("[ mpc10x_int: unimplemented write to "
171                              "offset 0x%x: data=0x%x ]\n", (int)                              "offset 0x%x: data=0x%x ]\n", (int)
172                              relative_addr, (int)idata);                              relative_addr, (int)idata);
173                  } else {                  } else {
174                          fatal("[ cpc700_int: unimplemented read from "                          fatal("[ mpc10x_int: unimplemented read from "
175                              "offset 0x%x ]\n", (int)relative_addr);                              "offset 0x%x ]\n", (int)relative_addr);
176                  }                  }
177          }          }
# Line 143  int dev_cpc700_int_access(struct cpu *cp Line 183  int dev_cpc700_int_access(struct cpu *cp
183  }  }
184    
185    
186  /*  DEVINIT(mpc10x)
  *  dev_cpc700_init():  
  */  
 struct cpc700_data *dev_cpc700_init(struct machine *machine, struct memory *mem)  
187  {  {
188          struct cpc700_data *d;          struct mpc10x_data *d;
189          char tmp[300];          char tmp[300];
190            int i;
191    
192          d = malloc(sizeof(struct cpc700_data));          CHECK_ALLOCATION(d = malloc(sizeof(struct mpc10x_data)));
193          if (d == NULL) {          memset(d, 0, sizeof(struct mpc10x_data));
194                  fprintf(stderr, "out of memory\n");  
195                  exit(1);          /*  Connect to the CPU's interrupt pin:  */
196            INTERRUPT_CONNECT(devinit->interrupt_path, d->ppc_irq);
197    
198            /*  Register 32 mpc10x interrupts:  */
199            for (i=0; i<32; i++) {
200                    struct interrupt template;
201                    char n[300];
202                    snprintf(n, sizeof(n), "%s.mpc10x.%i",
203                        devinit->interrupt_path, i);
204                    memset(&template, 0, sizeof(template));
205                    template.line = 1 << i;
206                    template.name = n;
207                    template.extra = d;
208                    template.interrupt_assert = mpc10x_interrupt_assert;
209                    template.interrupt_deassert = mpc10x_interrupt_deassert;
210                    interrupt_handler_register(&template);
211          }          }
         memset(d, 0, sizeof(struct cpc700_data));  
212    
213          /*  Register a PCI bus:  */          /*  Register a PCI bus:  */
214            snprintf(tmp, sizeof(tmp), "%s.mpc10x", devinit->interrupt_path);
215          d->pci_data = bus_pci_init(          d->pci_data = bus_pci_init(
216              0                   /*  pciirq: TODO  */,              devinit->machine,
217                tmp,                /*  pciirq path  */
218              0,                  /*  pci device io offset  */              0,                  /*  pci device io offset  */
219              0,                  /*  pci device mem offset  */              0,                  /*  pci device mem offset  */
220              CPC_PCI_IO_BASE,    /*  PCI portbase  */              MPC_PCI_IO_BASE,    /*  PCI portbase  */
221              CPC_PCI_MEM_BASE,   /*  PCI membase: TODO  */              MPC_PCI_MEM_BASE,   /*  PCI membase: TODO  */
222              0,                  /*  PCI irqbase: TODO  */              tmp,                /*  PCI irqbase  */
223              0,                  /*  ISA portbase: TODO  */              0,                  /*  ISA portbase: TODO  */
224              0,                  /*  ISA membase: TODO  */              0,                  /*  ISA membase: TODO  */
225              0);                 /*  ISA irqbase: TODO  */              tmp);               /*  ISA irqbase  */
226    
227          switch (machine->machine_type) {  #if 0
228          case MACHINE_PMPPC:          switch (devinit->machine->machine_type) {
229                  bus_pci_add(machine, d->pci_data, mem, 0, 0, 0,  
230                      "heuricon_pmppc");          case MACHINE_SANDPOINT:
231                    bus_pci_add(devinit->machine, d->pci_data,
232                        devinit->machine->memory, 0, 0, 0, "sandpoint_pci");
233                  break;                  break;
234          default:fatal("!\n! WARNING: cpc700 for non-implemented machine"  
235            default:fatal("!\n! WARNING: mpc10x for non-implemented machine"
236                      " type\n!\n");                      " type\n!\n");
237                  exit(1);                  exit(1);
238          }          }
239    #endif
240    
241          /*  PCI configuration registers:  */          /*  PCI configuration registers:  */
242          memory_device_register(mem, "cpc700_pci", CPC_PCICFGADR, 8,          memory_device_register(devinit->machine->memory, "mpc10x_pci",
243              dev_cpc700_pci_access, d, DM_DEFAULT, NULL);              MPC10X_MAPB_CNFG_DATA, 8, dev_mpc10x_pci_access, d, DM_DEFAULT, NULL);
244    
245          /*  Interrupt controller:  */          /*  Interrupt controller:  */
246          memory_device_register(mem, "cpc700_int", CPC_UIC_BASE, CPC_UIC_SIZE,          memory_device_register(devinit->machine->memory, "mpc10x_int",
247              dev_cpc700_int_access, d, DM_DEFAULT, NULL);              MPC_UIC_BASE, MPC_UIC_SIZE, dev_mpc10x_int_access, d,
248                DM_DEFAULT, NULL);
249    
250          /*  Two serial ports:  */          /*  Two serial ports:  */
251          snprintf(tmp, sizeof(tmp), "ns16550 irq=%i addr=0x%llx name2=tty0",          snprintf(tmp, sizeof(tmp), "ns16550 irq=%s.mpc10x.%i addr=0x%llx "
252              31 - CPC_IB_UART_0, (long long)CPC_COM0);              "name2=tty0", devinit->interrupt_path, 31 - MPC_IB_UART_0,
253          machine->main_console_handle = (size_t)device_add(machine, tmp);              (long long)MPC_COM0);
254          snprintf(tmp, sizeof(tmp), "ns16550 irq=%i addr=0x%llx name2=tty1",          devinit->machine->main_console_handle = (size_t)
255              31 - CPC_IB_UART_1, (long long)CPC_COM1);              device_add(devinit->machine, tmp);
256          device_add(machine, tmp);  #if 0
257            snprintf(tmp, sizeof(tmp), "ns16550 irq=%s.mpc10x.%i addr=0x%llx "
258                "name2=tty1", devinit->interrupt_path, 31 - MPC_IB_UART_1,
259                (long long)MPC_COM1);
260            device_add(devinit->machine, tmp);
261    #endif
262    
263          return d;          devinit->return_ptr = d->pci_data;
264    
265            return 1;
266  }  }
267    

Legend:
Removed from v.20  
changed lines
  Added in v.53

  ViewVC Help
Powered by ViewVC 1.1.26