/[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 61 by dpavlin, Fri Oct 12 22:06:53 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: mpc10x bridge (PCI and interrupt controller)
31     *  based on dev_uninorth.c
32   */   */
33    
34  #include <stdio.h>  #include <stdio.h>
# Line 37  Line 38 
38  #include "bus_pci.h"  #include "bus_pci.h"
39  #include "cpu.h"  #include "cpu.h"
40  #include "device.h"  #include "device.h"
41  #include "devices.h"  #include "interrupt.h"
42  #include "machine.h"  #include "machine.h"
43  #include "memory.h"  #include "memory.h"
44  #include "misc.h"  #include "misc.h"
45    
46  #include "cpc700reg.h"  #if 0
47    
48    #define PCI_VENDOR_ID_MOTOROLA          0x1057
49    #define MPC10X_BRIDGE_106       ((PCI_DEVICE_ID_MOTOROLA_MPC106 << 16) |  \
50                                      PCI_VENDOR_ID_MOTOROLA)
51    #define MPC10X_BRIDGE_8240      ((0x0003 << 16) | PCI_VENDOR_ID_MOTOROLA)
52    #define MPC10X_BRIDGE_107       ((0x0004 << 16) | PCI_VENDOR_ID_MOTOROLA)
53    #define MPC10X_BRIDGE_8245      ((0x0006 << 16) | PCI_VENDOR_ID_MOTOROLA)
54    
55  /*  #define MPC10X_MAPB_CNFG_ADDR           0xfec00000
56   *  dev_cpc700_pci_access():  #define MPC10X_MAPB_CNFG_DATA           0xfee00000
  *  
  *  Passes PCI indirect addr and data accesses onto bus_pci_access().  
  */  
 int dev_cpc700_pci_access(struct cpu *cpu, struct memory *mem,  
         uint64_t relative_addr, unsigned char *data, size_t len,  
         int writeflag, void *extra)  
 {  
         uint64_t idata = 0, odata = 0;  
         struct cpc700_data *d = extra;  
57    
58          if (writeflag == MEM_WRITE)  #define MPC10X_MAPB_ISA_IO_BASE         0xfe000000
59                  idata = memory_readmax64(cpu, data, len);  #define MPC10X_MAPB_ISA_MEM_BASE        0x80000000
60    #define MPC10X_MAPB_DRAM_OFFSET         0x00000000
61    
62          relative_addr += BUS_PCI_ADDR;  #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          if (writeflag == MEM_WRITE)  #define MPC10X_MAPB_PCI_MEM_OFFSET      (MPC10X_MAPB_ISA_MEM_BASE -     \
68                  bus_pci_access(cpu, mem, relative_addr, &idata,                                           MPC10X_MAPB_PCI_MEM_START)
                     len, writeflag, d->pci_data);  
         else  
                 bus_pci_access(cpu, mem, relative_addr, &odata,  
                     len, writeflag, d->pci_data);  
69    
70          if (writeflag == MEM_READ)  #endif
71                  memory_writemax64(cpu, data, len, odata);  
72    struct mpc10x_data {
73            int             pciirq;
74    
75            struct pci_data *pci_data;
76            uint64_t        cur_addr;
77    };
78    
79    
80    DEVICE_ACCESS(mpc10x_addr)
81    {
82            struct mpc10x_data *d = extra;
83    
84            if (writeflag == MEM_WRITE) {
85                    uint64_t idata = memory_readmax64(cpu, data, len
86                        | MEM_PCI_LITTLE_ENDIAN);
87                    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 {
98                            bus = 0;
99                            for (dev=11; dev<32; dev++)
100                                    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                            func = (idata >> 8) & 7;
107                            reg = idata & 0xff;
108                    }
109    
110                    bus_pci_setaddr(cpu, d->pci_data, bus, dev, func, reg);
111            } else {
112                    /*  TODO: is returning the current address like this
113                        the correct behaviour?  */
114                    memory_writemax64(cpu, data, len | MEM_PCI_LITTLE_ENDIAN,
115                        d->cur_addr);
116            }
117    
118          return 1;          return 1;
119  }  }
120    
121    
122  /*  DEVICE_ACCESS(mpc10x_data)
  *  dev_cpc700_int_access():  
  *  
  *  The interrupt controller.  
  */  
 int dev_cpc700_int_access(struct cpu *cpu, struct memory *mem,  
         uint64_t relative_addr, unsigned char *data, size_t len,  
         int writeflag, void *extra)  
123  {  {
124          struct cpc700_data *d = extra;          struct mpc10x_data *d = extra;
125          uint64_t idata = 0, odata = 0;          uint64_t idata = 0, odata = 0;
126    
127          if (writeflag == MEM_WRITE)          if (writeflag == MEM_WRITE)
128                  idata = memory_readmax64(cpu, data, len);                  idata = memory_readmax64(cpu, data, len|MEM_PCI_LITTLE_ENDIAN);
129    
130          switch (relative_addr) {          bus_pci_data_access(cpu, d->pci_data, writeflag == MEM_READ? &odata :
131                &idata, len, writeflag);
         case CPC_UIC_SR:  
                 /*  Status register (cleared by writing ones):  */  
                 if (writeflag == MEM_READ)  
                         odata = d->sr;  
                 else  
                         d->sr &= ~idata;  
                 break;  
   
         case CPC_UIC_SRS:  
                 /*  Status register set:  */  
                 if (writeflag == MEM_READ) {  
                         fatal("[ cpc700_int: read from CPC_UIC_SRS? ]\n");  
                         odata = d->sr;  
                 } else  
                         d->sr = idata;  
                 break;  
   
         case CPC_UIC_ER:  
                 /*  Enable register:  */  
                 if (writeflag == MEM_READ)  
                         odata = d->er;  
                 else  
                         d->er = idata;  
                 break;  
   
         case CPC_UIC_MSR:  
                 /*  Masked status:  */  
                 if (writeflag == MEM_READ)  
                         odata = d->sr & d->er;  
                 else  
                         fatal("[ cpc700_int: write to CPC_UIC_MSR? ]\n");  
                 break;  
   
         default:if (writeflag == MEM_WRITE) {  
                         fatal("[ cpc700_int: unimplemented write to "  
                             "offset 0x%x: data=0x%x ]\n", (int)  
                             relative_addr, (int)idata);  
                 } else {  
                         fatal("[ cpc700_int: unimplemented read from "  
                             "offset 0x%x ]\n", (int)relative_addr);  
                 }  
         }  
132    
133          if (writeflag == MEM_READ)          if (writeflag == MEM_READ)
134                  memory_writemax64(cpu, data, len, odata);                  memory_writemax64(cpu, data, len|MEM_PCI_LITTLE_ENDIAN, odata);
135    
136          return 1;          return 1;
137  }  }
138    
139    
140  /*  struct pci_data *dev_mpc10x_init(struct machine *machine, struct memory *mem,
141   *  dev_cpc700_init():          uint64_t addr, int isa_irqbase, int pciirq)
  */  
 struct cpc700_data *dev_cpc700_init(struct machine *machine, struct memory *mem)  
142  {  {
143          struct cpc700_data *d;          struct mpc10x_data *d;
144          char tmp[300];  //      char tmp[100];
145            uint64_t pci_io_offset, pci_mem_offset;
146          d = malloc(sizeof(struct cpc700_data));          uint64_t isa_portbase = 0, isa_membase = 0;
147          if (d == NULL) {          uint64_t pci_portbase = 0, pci_membase = 0;
148                  fprintf(stderr, "out of memory\n");  
149                  exit(1);          CHECK_ALLOCATION(d = malloc(sizeof(struct mpc10x_data)));
150          }          memset(d, 0, sizeof(struct mpc10x_data));
151          memset(d, 0, sizeof(struct cpc700_data));  
152            d->pciirq = pciirq;
153          /*  Register a PCI bus:  */  
154          d->pci_data = bus_pci_init(          pci_io_offset  = 0x00000000ULL;
155              0                   /*  pciirq: TODO  */,          pci_mem_offset = 0x00000000ULL;
156              0,                  /*  pci device io offset  */          pci_portbase   = 0xd0000000ULL;
157              0,                  /*  pci device mem offset  */          pci_membase    = 0xd1000000ULL;
158              CPC_PCI_IO_BASE,    /*  PCI portbase  */          isa_portbase   = 0xd2000000ULL;
159              CPC_PCI_MEM_BASE,   /*  PCI membase: TODO  */          isa_membase    = 0xd3000000ULL;
160              0,                  /*  PCI irqbase: TODO  */  
161              0,                  /*  ISA portbase: TODO  */          /*  Create a PCI bus:  */
162              0,                  /*  ISA membase: TODO  */          d->pci_data = bus_pci_init(machine, "ZZZ_irq_stuff",
163              0);                 /*  ISA irqbase: TODO  */              pci_io_offset, pci_mem_offset,
164                pci_portbase, pci_membase, "XXX_pci_irqbase",
165          switch (machine->machine_type) {              isa_portbase, isa_membase, "YYY_isa_irqbase");
166          case MACHINE_PMPPC:  
167                  bus_pci_add(machine, d->pci_data, mem, 0, 0, 0,          /*  Add the PCI glue for the controller itself:  */
168                      "heuricon_pmppc");          bus_pci_add(machine, d->pci_data, mem, 0, 0x1f, 0, "mpc10x");
169                  break;  
170          default:fatal("!\n! WARNING: cpc700 for non-implemented machine"          /*  ADDR and DATA configuration ports:  */
171                      " type\n!\n");          memory_device_register(mem, "mpc10x_pci_addr", addr + 0xc00000,
172                  exit(1);              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);
         /*  PCI configuration registers:  */  
         memory_device_register(mem, "cpc700_pci", CPC_PCICFGADR, 8,  
             dev_cpc700_pci_access, d, DM_DEFAULT, NULL);  
   
         /*  Interrupt controller:  */  
         memory_device_register(mem, "cpc700_int", CPC_UIC_BASE, CPC_UIC_SIZE,  
             dev_cpc700_int_access, d, DM_DEFAULT, NULL);  
   
         /*  Two serial ports:  */  
         snprintf(tmp, sizeof(tmp), "ns16550 irq=%i addr=0x%llx name2=tty0",  
             31 - CPC_IB_UART_0, (long long)CPC_COM0);  
         machine->main_console_handle = (size_t)device_add(machine, tmp);  
         snprintf(tmp, sizeof(tmp), "ns16550 irq=%i addr=0x%llx name2=tty1",  
             31 - CPC_IB_UART_1, (long long)CPC_COM1);  
         device_add(machine, tmp);  
175    
176          return d;          return d->pci_data;
177  }  }
178    

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

  ViewVC Help
Powered by ViewVC 1.1.26