/[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

revision 57 by dpavlin, Thu Oct 11 18:57:32 2007 UTC revision 61 by dpavlin, Fri Oct 12 22:06:53 2007 UTC
# Line 27  Line 27 
27   *   *
28   *  $Id: dev_mpc10x.c,v 1.12 2007/06/15 18:13:04 debug Exp $   *  $Id: dev_mpc10x.c,v 1.12 2007/06/15 18:13:04 debug Exp $
29   *   *
30   *  COMMENT: IBM mpc10x bridge (PCI and interrupt controller)   *  COMMENT: mpc10x bridge (PCI and interrupt controller)
31     *  based on dev_uninorth.c
32   */   */
33    
34  #include <stdio.h>  #include <stdio.h>
# Line 42  Line 43 
43  #include "memory.h"  #include "memory.h"
44  #include "misc.h"  #include "misc.h"
45    
46  #include "mpc10xreg.h"  #if 0
   
   
 struct mpc10x_data {  
         struct interrupt ppc_irq;       /*  Connected to the CPU  */  
   
         uint32_t        sr;             /*  Interrupt Status register  */  
         uint32_t        er;             /*  Interrupt Enable register  */  
   
         struct pci_data *pci_data;      /*  PCI bus  */  
 };  
   
   
 void mpc10x_interrupt_assert(struct interrupt *interrupt)  
 {  
         struct mpc10x_data *d = interrupt->extra;  
         d->sr |= interrupt->line;  
         if (d->sr & d->er)  
                 INTERRUPT_ASSERT(d->ppc_irq);  
 }  
 void mpc10x_interrupt_deassert(struct interrupt *interrupt)  
 {  
         struct mpc10x_data *d = interrupt->extra;  
         d->sr &= ~interrupt->line;  
         if (!(d->sr & d->er))  
                 INTERRUPT_DEASSERT(d->ppc_irq);  
 }  
   
   
 /*  
  *  dev_mpc10x_pci_access():  
  *  
  *  Passes PCI indirect addr and data accesses onto bus_pci.  
  */  
 DEVICE_ACCESS(mpc10x_pci)  
 {  
         uint64_t idata = 0, odata = 0;  
         int bus, dev, func, reg;  
         struct mpc10x_data *d = extra;  
   
         if (writeflag == MEM_WRITE) {  
                 idata = memory_readmax64(cpu, data, len|MEM_PCI_LITTLE_ENDIAN);  
                 debug("mpc10x_pci WRITE offset 0x%x: 0x%x\n", relative_addr, odata);  
         }  
   
         debug("relative: %d i: 0x%x o: 0x%x data: %s len: %d\n", relative_addr,idata, odata, data, len );  
   
         switch (relative_addr) {  
         case 0: /*  Address:  */  
                 bus_pci_decompose_1(idata, &bus, &dev, &func, &reg);  
                 bus_pci_setaddr(cpu, d->pci_data, bus, dev, func, reg);  
                 break;  
   
         case 4: /*  Data:  */  
                 bus_pci_data_access(cpu, d->pci_data, writeflag == MEM_READ?  
                     &odata : &idata, len, writeflag);  
                 break;  
         }  
47    
48  #define PCI_VENDOR_ID_MOTOROLA          0x1057  #define PCI_VENDOR_ID_MOTOROLA          0x1057
49  #define MPC10X_BRIDGE_106       ((PCI_DEVICE_ID_MOTOROLA_MPC106 << 16) |  \  #define MPC10X_BRIDGE_106       ((PCI_DEVICE_ID_MOTOROLA_MPC106 << 16) |  \
# Line 108  DEVICE_ACCESS(mpc10x_pci) Line 52  DEVICE_ACCESS(mpc10x_pci)
52  #define MPC10X_BRIDGE_107       ((0x0004 << 16) | PCI_VENDOR_ID_MOTOROLA)  #define MPC10X_BRIDGE_107       ((0x0004 << 16) | PCI_VENDOR_ID_MOTOROLA)
53  #define MPC10X_BRIDGE_8245      ((0x0006 << 16) | PCI_VENDOR_ID_MOTOROLA)  #define MPC10X_BRIDGE_8245      ((0x0006 << 16) | PCI_VENDOR_ID_MOTOROLA)
54    
55          debug("i: 0x%x o: 0x%x\n", idata, odata );  #define MPC10X_MAPB_CNFG_ADDR           0xfec00000
56          if (writeflag == MEM_READ) {  #define MPC10X_MAPB_CNFG_DATA           0xfee00000
                 memory_writemax64(cpu, data, len|MEM_PCI_LITTLE_ENDIAN, odata);  
                 odata = MPC10X_BRIDGE_8245;  
                 debug("mpc10x_pci READ offset 0x%x: 0x%x\n", relative_addr, odata);  
         }  
57    
58          return 1;  #define MPC10X_MAPB_ISA_IO_BASE         0xfe000000
59  }  #define MPC10X_MAPB_ISA_MEM_BASE        0x80000000
60    #define MPC10X_MAPB_DRAM_OFFSET         0x00000000
61    
62    #define MPC10X_MAPB_PCI_IO_START        0x00000000
63    #define MPC10X_MAPB_PCI_IO_END         (0x00c00000 - 1)
64    #define MPC10X_MAPB_PCI_MEM_START       0x80000000
65    #define MPC10X_MAPB_PCI_MEM_END        (0xc0000000 - 1)
66    
67    #define MPC10X_MAPB_PCI_MEM_OFFSET      (MPC10X_MAPB_ISA_MEM_BASE -     \
68                                             MPC10X_MAPB_PCI_MEM_START)
69    
70  /*  #endif
  *  dev_mpc10x_int_access():  
  *  
  *  The interrupt controller.  
  */  
 DEVICE_ACCESS(mpc10x_int)  
 {  
         struct mpc10x_data *d = extra;  
         uint64_t idata = 0, odata = 0;  
71    
72          if (writeflag == MEM_WRITE)  struct mpc10x_data {
73                  idata = memory_readmax64(cpu, data, len);          int             pciirq;
74    
75          switch (relative_addr) {          struct pci_data *pci_data;
76            uint64_t        cur_addr;
77    };
78    
         case MPC_UIC_SR:  
                 /*  Status register (cleared by writing ones):  */  
                 if (writeflag == MEM_READ) {  
                         odata = d->sr;  
                 } else {  
                         d->sr &= ~idata;  
                         if (!(d->sr & d->er))  
                                 INTERRUPT_DEASSERT(d->ppc_irq);  
                 }  
                 break;  
79    
80          case MPC_UIC_SRS:  DEVICE_ACCESS(mpc10x_addr)
81                  /*  Status register set:  */  {
82                  if (writeflag == MEM_READ) {          struct mpc10x_data *d = extra;
                         fatal("[ mpc10x_int: read from MPC_UIC_SRS? ]\n");  
                         odata = d->sr;  
                 } else {  
                         d->sr = idata;  
                         if (d->sr & d->er)  
                                 INTERRUPT_ASSERT(d->ppc_irq);  
                         else  
                                 INTERRUPT_DEASSERT(d->ppc_irq);  
                 }  
                 break;  
83    
84          case MPC_UIC_ER:          if (writeflag == MEM_WRITE) {
85                  /*  Enable register:  */                  uint64_t idata = memory_readmax64(cpu, data, len
86                  if (writeflag == MEM_READ) {                      | MEM_PCI_LITTLE_ENDIAN);
87                          odata = d->er;                  int bus, dev, func, reg;
88    
89                    d->cur_addr = idata;
90                    if (idata == 0)
91                            return 0;
92    
93                    /*  Decompose the Uni-North tag:  */
94                    if (idata & 1) {
95                            idata &= ~1;
96                            bus_pci_decompose_1(idata, &bus, &dev, &func, &reg);
97                  } else {                  } else {
98                          d->er = idata;                          bus = 0;
99                          if (d->sr & d->er)                          for (dev=11; dev<32; dev++)
100                                  INTERRUPT_ASSERT(d->ppc_irq);                                  if (idata & (1 << dev))
101                          else                                          break;
102                                  INTERRUPT_DEASSERT(d->ppc_irq);                          if (dev == 32)
103                  }                                  fatal("[ dev_mpc10x_addr_access: no dev? "
104                  break;                                      "idata=0x%08x ]\n", (int)idata);
105    
106          case MPC_UIC_MSR:                          func = (idata >> 8) & 7;
107                  /*  Masked status:  */                          reg = idata & 0xff;
                 if (writeflag == MEM_READ) {  
                         odata = d->sr & d->er;  
                 } else {  
                         fatal("[ mpc10x_int: write to MPC_UIC_MSR? ]\n");  
108                  }                  }
                 break;  
109    
110          default:if (writeflag == MEM_WRITE) {                  bus_pci_setaddr(cpu, d->pci_data, bus, dev, func, reg);
111                          fatal("[ mpc10x_int: unimplemented write to "          } else {
112                              "offset 0x%x: data=0x%x ]\n", (int)                  /*  TODO: is returning the current address like this
113                              relative_addr, (int)idata);                      the correct behaviour?  */
114                  } else {                  memory_writemax64(cpu, data, len | MEM_PCI_LITTLE_ENDIAN,
115                          fatal("[ mpc10x_int: unimplemented read from "                      d->cur_addr);
                             "offset 0x%x ]\n", (int)relative_addr);  
                 }  
116          }          }
117    
         if (writeflag == MEM_READ)  
                 memory_writemax64(cpu, data, len, odata);  
   
118          return 1;          return 1;
119  }  }
120    
121  /*  
122   *  dev_mpc10x_config_access():  DEVICE_ACCESS(mpc10x_data)
  *  
  *  Configuration  
  */  
 DEVICE_ACCESS(mpc10x_config)  
123  {  {
124            struct mpc10x_data *d = extra;
125          uint64_t idata = 0, odata = 0;          uint64_t idata = 0, odata = 0;
 //      struct mpc10x_data *d = extra;  
   
         if (writeflag == MEM_WRITE) {  
                 idata = memory_readmax64(cpu, data, len);  
                 debug("mpc10x_config WRITE offset 0x%x: 0x%x [old: 0x%x]\n", relative_addr, odata, idata);  
         }  
126    
127          debug("relative: %d i: 0x%x o: 0x%x data: %s len: %d\n", relative_addr,idata, odata, data, len );          if (writeflag == MEM_WRITE)
128                    idata = memory_readmax64(cpu, data, len|MEM_PCI_LITTLE_ENDIAN);
         switch (relative_addr) {  
         case 0:  
   
 #define PCI_VENDOR_ID_MOTOROLA          0x1057  
 #define MPC10X_BRIDGE_106       ((PCI_DEVICE_ID_MOTOROLA_MPC106 << 16) |  \  
                                   PCI_VENDOR_ID_MOTOROLA)  
 #define MPC10X_BRIDGE_8240      ((0x0003 << 16) | PCI_VENDOR_ID_MOTOROLA)  
 #define MPC10X_BRIDGE_107       ((0x0004 << 16) | PCI_VENDOR_ID_MOTOROLA)  
 #define MPC10X_BRIDGE_8245      ((0x0006 << 16) | PCI_VENDOR_ID_MOTOROLA)  
129    
130                  return MPC10X_BRIDGE_8245;          bus_pci_data_access(cpu, d->pci_data, writeflag == MEM_READ? &odata :
131          }              &idata, len, writeflag);
132    
133          debug("i: 0x%x o: 0x%x\n", idata, odata );          if (writeflag == MEM_READ)
134          if (writeflag == MEM_READ) {                  memory_writemax64(cpu, data, len|MEM_PCI_LITTLE_ENDIAN, odata);
                 odata = MPC10X_BRIDGE_8245;  
                 memory_writemax64(cpu, data, len, odata);  
                 debug("mpc10x_config READ offset 0x%x: 0x%x\n", relative_addr, odata);  
         }  
135    
136          return 1;          return 1;
137  }  }
138    
139  DEVINIT(mpc10x)  
140    struct pci_data *dev_mpc10x_init(struct machine *machine, struct memory *mem,
141            uint64_t addr, int isa_irqbase, int pciirq)
142  {  {
143          struct mpc10x_data *d;          struct mpc10x_data *d;
144          char tmp[300];  //      char tmp[100];
145          int i;          uint64_t pci_io_offset, pci_mem_offset;
146            uint64_t isa_portbase = 0, isa_membase = 0;
147            uint64_t pci_portbase = 0, pci_membase = 0;
148    
149          CHECK_ALLOCATION(d = malloc(sizeof(struct mpc10x_data)));          CHECK_ALLOCATION(d = malloc(sizeof(struct mpc10x_data)));
150          memset(d, 0, sizeof(struct mpc10x_data));          memset(d, 0, sizeof(struct mpc10x_data));
151    
152          /*  Connect to the CPU's interrupt pin:  */          d->pciirq = pciirq;
         INTERRUPT_CONNECT(devinit->interrupt_path, d->ppc_irq);  
   
         /*  Register 32 mpc10x interrupts:  */  
         for (i=0; i<32; i++) {  
                 struct interrupt template;  
                 char n[300];  
                 snprintf(n, sizeof(n), "%s.mpc10x.%i",  
                     devinit->interrupt_path, i);  
                 memset(&template, 0, sizeof(template));  
                 template.line = 1 << i;  
                 template.name = n;  
                 template.extra = d;  
                 template.interrupt_assert = mpc10x_interrupt_assert;  
                 template.interrupt_deassert = mpc10x_interrupt_deassert;  
                 interrupt_handler_register(&template);  
         }  
153    
154          /*  Register a PCI bus:  */          pci_io_offset  = 0x00000000ULL;
155          snprintf(tmp, sizeof(tmp), "%s.mpc10x", devinit->interrupt_path);          pci_mem_offset = 0x00000000ULL;
156          d->pci_data = bus_pci_init(          pci_portbase   = 0xd0000000ULL;
157              devinit->machine,          pci_membase    = 0xd1000000ULL;
158              tmp,                /*  pciirq path  */          isa_portbase   = 0xd2000000ULL;
159              0xfc000000,         /*  pci device io offset  */          isa_membase    = 0xd3000000ULL;
160              0xfcc00000,         /*  pci device mem offset  */  
161              0xfec00000,         /*  PCI portbase  */          /*  Create a PCI bus:  */
162              0x80000000,         /*  PCI membase: TODO  */          d->pci_data = bus_pci_init(machine, "ZZZ_irq_stuff",
163              tmp,                /*  PCI irqbase  */              pci_io_offset, pci_mem_offset,
164              0,                  /*  ISA portbase: TODO  */              pci_portbase, pci_membase, "XXX_pci_irqbase",
165              0,                  /*  ISA membase: TODO  */              isa_portbase, isa_membase, "YYY_isa_irqbase");
166              tmp);               /*  ISA irqbase  */  
167            /*  Add the PCI glue for the controller itself:  */
168          /* PCI host bridge */          bus_pci_add(machine, d->pci_data, mem, 0, 0x1f, 0, "mpc10x");
169          bus_pci_add(devinit->machine, d->pci_data,  
170                  devinit->machine->memory, 0, 0, 0, "mpc10x_host_bridge");          /*  ADDR and DATA configuration ports:  */
171            memory_device_register(mem, "mpc10x_pci_addr", addr + 0xc00000,
172          /*  MPC10x configuration  */              4, dev_mpc10x_addr_access, d, DM_DEFAULT, NULL);
173          memory_device_register(devinit->machine->memory, "mpc10x_config",          memory_device_register(mem, "mpc10x_pci_data", addr + 0xe00000,
174              0xfec00000, 8, dev_mpc10x_config_access, d, DM_DEFAULT, NULL);              8, dev_mpc10x_data_access, d, DM_DEFAULT, NULL);
   
         /*  PCI configuration registers:  */  
         memory_device_register(devinit->machine->memory, "mpc10x_pci",  
             0xfee00000, 8, dev_mpc10x_pci_access, d, DM_DEFAULT, NULL);  
   
         /*  Interrupt controller:  */  
         memory_device_register(devinit->machine->memory, "mpc10x_int",  
             MPC_UIC_BASE, MPC_UIC_SIZE, dev_mpc10x_int_access, d,  
             DM_DEFAULT, NULL);  
   
         /*  Two serial ports:  */  
         snprintf(tmp, sizeof(tmp), "ns16550 irq=%s.mpc10x.%i addr=0x%llx "  
             "name2=tty0", devinit->interrupt_path, 31 - MPC_IB_UART_0,  
             (long long)MPC_COM0);  
         devinit->machine->main_console_handle = (size_t)  
             device_add(devinit->machine, tmp);  
 #if 0  
         snprintf(tmp, sizeof(tmp), "ns16550 irq=%s.mpc10x.%i addr=0x%llx "  
             "name2=tty1", devinit->interrupt_path, 31 - MPC_IB_UART_1,  
             (long long)MPC_COM1);  
         device_add(devinit->machine, tmp);  
 #endif  
175    
176          devinit->return_ptr = d->pci_data;          return d->pci_data;
   
         return 1;  
177  }  }
178    

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

  ViewVC Help
Powered by ViewVC 1.1.26