/[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 60 by dpavlin, Fri Oct 12 19:40:03 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   *  dev_mpc10x_int_access():                                           MPC10X_MAPB_PCI_MEM_START)
  *  
  *  The interrupt controller.  
  */  
 DEVICE_ACCESS(mpc10x_int)  
 {  
         struct mpc10x_data *d = extra;  
         uint64_t idata = 0, odata = 0;  
69    
70          if (writeflag == MEM_WRITE)  #endif
                 idata = memory_readmax64(cpu, data, len);  
71    
72          switch (relative_addr) {  struct mpc10x_data {
73            int             pciirq;
74    
75          case MPC_UIC_SR:          struct pci_data *pci_data;
76                  /*  Status register (cleared by writing ones):  */          uint64_t        cur_addr;
77                  if (writeflag == MEM_READ) {  };
                         odata = d->sr;  
                 } else {  
                         d->sr &= ~idata;  
                         if (!(d->sr & d->er))  
                                 INTERRUPT_DEASSERT(d->ppc_irq);  
                 }  
                 break;  
78    
         case MPC_UIC_SRS:  
                 /*  Status register set:  */  
                 if (writeflag == MEM_READ) {  
                         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;  
79    
80          case MPC_UIC_ER:  DEVICE_ACCESS(mpc10x_addr)
81                  /*  Enable register:  */  {
82                  if (writeflag == MEM_READ) {          struct mpc10x_data *d = extra;
                         odata = d->er;  
                 } else {  
                         d->er = idata;  
                         if (d->sr & d->er)  
                                 INTERRUPT_ASSERT(d->ppc_irq);  
                         else  
                                 INTERRUPT_DEASSERT(d->ppc_irq);  
                 }  
                 break;  
83    
84          case MPC_UIC_MSR:          if (writeflag == MEM_WRITE) {
85                  /*  Masked status:  */                  uint64_t idata = memory_readmax64(cpu, data, len
86                  if (writeflag == MEM_READ) {                      | MEM_PCI_LITTLE_ENDIAN);
87                          odata = d->sr & 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                          fatal("[ mpc10x_int: write to MPC_UIC_MSR? ]\n");                          bus = 0;
99                  }                          for (dev=11; dev<32; dev++)
100                  break;                                  if (idata & (1 << dev))
101                                            break;
102                            if (dev == 32)
103                                    fatal("[ dev_mpc10x_addr_access: no dev? "
104                                        "idata=0x%08x ]\n", (int)idata);
105    
106          default:if (writeflag == MEM_WRITE) {                          func = (idata >> 8) & 7;
107                          fatal("[ mpc10x_int: unimplemented write to "                          reg = idata & 0xff;
                             "offset 0x%x: data=0x%x ]\n", (int)  
                             relative_addr, (int)idata);  
                 } else {  
                         fatal("[ mpc10x_int: unimplemented read from "  
                             "offset 0x%x ]\n", (int)relative_addr);  
108                  }                  }
         }  
   
         if (writeflag == MEM_READ)  
                 memory_writemax64(cpu, data, len, odata);  
   
         return 1;  
 }  
   
 /*  
  *  dev_mpc10x_config_access():  
  *  
  *  Configuration  
  */  
   
 DEVICE_ACCESS(mpc10x_config)  
 {  
         uint64_t idata = 0, odata = 0;  
109    
110          debug("mpc10x_config relative: %d i: 0x%x o: 0x%x data: %x len: %x write: %x w: %x r: %x\n", relative_addr,idata, odata, data, len, writeflag, MEM_WRITE, MEM_READ );                  bus_pci_setaddr(cpu, d->pci_data, bus, dev, func, reg);
111          if (writeflag == MEM_WRITE) {          } else {
112                  idata = memory_readmax64(cpu, data, len);                  /*  TODO: is returning the current address like this
113                  debug("[ mpc10x_config WRITE offset 0x%x: 0x%x odata: 0x%x data: 0x%x len: %d ]\n", relative_addr, idata, odata, data, len);                      the correct behaviour?  */
114          }                  memory_writemax64(cpu, data, len | MEM_PCI_LITTLE_ENDIAN,
115          if (writeflag == MEM_READ) {                      d->cur_addr);
                 fatal("[ mpc10x_config: read! ]\n");  
116          }          }
117    
118          return 1;          return 1;
119  }  }
120    
 #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)  
121    
122  DEVICE_ACCESS(mpc10x_data)  DEVICE_ACCESS(mpc10x_data)
123  {  {
124            struct mpc10x_data *d = extra;
125          uint64_t idata = 0, odata = 0;          uint64_t idata = 0, odata = 0;
126    
127          debug("mpc10x_data: relative: %d i: 0x%x o: 0x%x data: %s len: %d write: %d\n", relative_addr,idata, odata, data, len, writeflag );          if (writeflag == MEM_WRITE)
         if (writeflag == MEM_WRITE) {  
128                  idata = memory_readmax64(cpu, data, len|MEM_PCI_LITTLE_ENDIAN);                  idata = memory_readmax64(cpu, data, len|MEM_PCI_LITTLE_ENDIAN);
129                  fatal("[ mpc10x_data: write -> %x ]\n", (int)idata);  
130          }          bus_pci_data_access(cpu, d->pci_data, writeflag == MEM_READ? &odata :
131          if (writeflag == MEM_READ) {              &idata, len, writeflag);
132                  odata = MPC10X_BRIDGE_8245;  
133            if (writeflag == MEM_READ)
134                  memory_writemax64(cpu, data, len|MEM_PCI_LITTLE_ENDIAN, odata);                  memory_writemax64(cpu, data, len|MEM_PCI_LITTLE_ENDIAN, odata);
                 debug("odata = %x\n", (int)odata);  
                 debug("[ mpc10x_data: READ offset 0x%x: 0x%x odata: 0x%x data: 0x%x len: %d ]\n", relative_addr, idata, odata, data, len);  
         }  
135    
136          return 1;          return 1;
137  }  }
138    
139    
140  DEVINIT(mpc10x)  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);  
         }  
   
 #define MPC10X_MAPB_CNFG_ADDR           0xfec00000  
 #define MPC10X_MAPB_CNFG_DATA           0xfee00000  
   
 #define MPC10X_MAPB_ISA_IO_BASE         0xfe000000  
 #define MPC10X_MAPB_ISA_MEM_BASE        0x80000000  
 #define MPC10X_MAPB_DRAM_OFFSET         0x00000000  
   
 #define MPC10X_MAPB_PCI_IO_START        0x00000000  
 #define MPC10X_MAPB_PCI_IO_END         (0x00c00000 - 1)  
 #define MPC10X_MAPB_PCI_MEM_START       0x80000000  
 #define MPC10X_MAPB_PCI_MEM_END        (0xc0000000 - 1)  
   
 #define MPC10X_MAPB_PCI_MEM_OFFSET      (MPC10X_MAPB_ISA_MEM_BASE -     \  
                                          MPC10X_MAPB_PCI_MEM_START)  
   
153    
154            pci_io_offset  = 0x00000000ULL;
155            pci_mem_offset = 0x00000000ULL;
156            pci_portbase   = 0xd0000000ULL;
157            pci_membase    = 0xd1000000ULL;
158            isa_portbase   = 0xd2000000ULL;
159            isa_membase    = 0xd3000000ULL;
160    
161            /*  Create a PCI bus:  */
162            d->pci_data = bus_pci_init(machine, "ZZZ_irq_stuff",
163                pci_io_offset, pci_mem_offset,
164                pci_portbase, pci_membase, "XXX_pci_irqbase",
165                isa_portbase, isa_membase, "YYY_isa_irqbase");
166    
167            /*  Add the PCI glue for the controller itself:  */
168            bus_pci_add(machine, d->pci_data, mem, 0, 0x1f, 0, "mpc10x");
169    
170            /*  ADDR and DATA configuration ports:  */
171            memory_device_register(mem, "mpc10x_pci_addr", addr + 0xc00000,
172                4, dev_mpc10x_addr_access, d, DM_DEFAULT, NULL);
173            memory_device_register(mem, "mpc10x_pci_data", addr + 0xe00000,
174                8, dev_mpc10x_data_access, d, DM_DEFAULT, NULL);
175    
176          /*  Register a PCI bus:  */          return d->pci_data;
         snprintf(tmp, sizeof(tmp), "%s.mpc10x", devinit->interrupt_path);  
         d->pci_data = bus_pci_init(  
             devinit->machine,  
             tmp,                /*  pciirq path  */  
             0x00000000,         /*  pci device io offset  */  
             0x00000000,         /*  pci device mem offset  */  
             0xfe000000,         /*  PCI portbase  */  
             0x80000000,         /*  PCI membase: TODO  */  
             tmp,                /*  PCI irqbase  */  
             0xfe000000,         /*  ISA portbase: TODO  */  
             0x80000000,         /*  ISA membase: TODO  */  
             tmp);               /*  ISA irqbase  */  
   
         /* PCI host bridge */  
         bus_pci_add(devinit->machine, d->pci_data,  
                 devinit->machine->memory, 0, 0, 0, "mpc10x_host_bridge");  
   
         /*  MPC10x configuration  */  
         memory_device_register(devinit->machine->memory, "mpc10x_config",  
                 0xfec00000, 1, dev_mpc10x_config_access, d, DM_DEFAULT, NULL);  
         memory_device_register(devinit->machine->memory, "mpc10x_data",  
                 0xfee00000, 8, dev_mpc10x_data_access, d, DM_DEFAULT, NULL);  
   
 #if 0  
         /*  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);  
 #endif  
   
         /*  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  
   
         devinit->return_ptr = d->pci_data;  
   
         return 1;  
177  }  }
178    

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

  ViewVC Help
Powered by ViewVC 1.1.26