1 #include <console/console.h>
4 #include <device/device.h>
5 #include <device/pci.h>
6 #include <device/pci_ids.h>
7 #include <device/hypertransport.h>
14 * set up basic things ... PAR should NOT go here, as it might change with the mainboard.
16 static void cpu_init(device_t dev)
18 unsigned long *l = (unsigned long *) 0xfffef088;
20 for(i = 0; i < 16; i++, l++)
21 printk_err("Par%d: 0x%lx\n", i, *l);
23 printk_spew("SC520 random fixup ...\n");
28 static struct device_operations cpu_operations = {
29 .read_resources = pci_dev_read_resources,
30 .set_resources = pci_dev_set_resources,
31 .enable_resources = pci_dev_enable_resources,
37 static struct pci_driver cpu_driver __pci_driver = {
38 .ops = &cpu_operations,
39 .vendor = PCI_VENDOR_ID_AMD,
45 #define BRIDGE_IO_MASK (IORESOURCE_IO | IORESOURCE_MEM)
47 static void pci_domain_read_resources(device_t dev)
49 struct resource *resource;
50 printk_spew("%s\n", __FUNCTION__);
51 /* Initialize the system wide io space constraints */
52 resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0,0));
53 resource->limit = 0xffffUL;
54 resource->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED;
56 /* Initialize the system wide memory resources constraints */
57 resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1,0));
58 resource->limit = 0xffffffffULL;
59 resource->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED;
62 static void ram_resource(device_t dev, unsigned long index,
63 unsigned long basek, unsigned long sizek)
65 struct resource *resource;
66 printk_spew("%s sizek 0x%x\n", __FUNCTION__, sizek);
70 resource = new_resource(dev, index);
71 resource->base = ((resource_t)basek) << 10;
72 resource->size = ((resource_t)sizek) << 10;
73 resource->flags = IORESOURCE_MEM | IORESOURCE_CACHEABLE | \
74 IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
77 static void tolm_test(void *gp, struct device *dev, struct resource *new)
79 struct resource **best_p = gp;
80 struct resource *best;
82 if (!best || (best->base > new->base)) {
88 static uint32_t find_pci_tolm(struct bus *bus)
92 printk_spew("%s\n", __FUNCTION__);
94 search_bus_resources(bus, IORESOURCE_MEM, IORESOURCE_MEM, tolm_test, &min);
96 if (min && tolm > min->base) {
99 printk_spew("%s returns 0x%x\n", __FUNCTION__, tolm);
103 static void pci_domain_set_resources(device_t dev)
107 printk_spew("%s\n", __FUNCTION__);
108 pci_tolm = find_pci_tolm(&dev->link[0]);
109 mc_dev = dev->link[0].children;
111 unsigned long tomk, tolmk;
112 // unsigned char rambits;
116 for(rambits = 0, i = 0; i < sizeof(ramregs)/sizeof(ramregs[0]); i++) {
118 reg = pci_read_config8(mc_dev, ramregs[i]);
119 /* these are ENDING addresses, not sizes.
120 * if there is memory in this slot, then reg will be > rambits.
121 * So we just take the max, that gives us total.
122 * We take the highest one to cover for once and future linuxbios
123 * bugs. We warn about bugs.
128 printk_err("ERROR! register 0x%x is not set!\n",
131 printk_debug("I would set ram size to 0x%x Kbytes\n", (rambits)*8*1024);
132 tomk = rambits*8*1024;
135 /* Compute the top of Low memory */
136 tolmk = pci_tolm >> 10;
138 /* The PCI hole does does not overlap the memory.
142 /* Report the memory regions */
144 ram_resource(dev, idx++, 0, tolmk);
146 assign_resources(&dev->link[0]);
149 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max)
151 printk_spew("%s\n", __FUNCTION__);
152 max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0, 0), 0xff, max);
156 static struct device_operations pci_domain_ops = {
157 .read_resources = pci_domain_read_resources,
158 .set_resources = pci_domain_set_resources,
159 .enable_resources = enable_childrens_resources,
161 .scan_bus = pci_domain_scan_bus,
164 static void cpu_bus_init(device_t dev)
166 printk_spew("cpu_bus_init\n");
169 static void cpu_bus_noop(device_t dev)
173 static struct device_operations cpu_bus_ops = {
174 .read_resources = cpu_bus_noop,
175 .set_resources = cpu_bus_noop,
176 .enable_resources = cpu_bus_noop,
177 .init = cpu_bus_init,
181 static void enable_dev(struct device *dev)
183 printk_spew("%s\n", __FUNCTION__);
184 /* Set the operations if it is a special bus type */
185 if (dev->path.type == DEVICE_PATH_PCI_DOMAIN) {
186 dev->ops = &pci_domain_ops;
189 else if (dev->path.type == DEVICE_PATH_APIC_CLUSTER) {
190 dev->ops = &cpu_bus_ops;
195 struct chip_operations cpu_amd_sc520_ops = {
196 CHIP_NAME("AMD SC520")
197 .enable_dev = enable_dev,