Revision: linuxbios@linuxbios.org--devel/freebios--devel--2.0--patch-54
[coreboot.git] / src / cpu / amd / sc520 / sc520.c
1 #include <console/console.h>
2 #include <arch/io.h>
3 #include <stdint.h>
4 #include <device/device.h>
5 #include <device/pci.h>
6 #include <device/pci_ids.h>
7 #include <device/hypertransport.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <bitops.h>
11 #include "chip.h"
12
13 /*
14  * set up basic things ... PAR should NOT go here, as it might change with the mainboard. 
15  */
16 static void cpu_init(device_t dev) 
17 {
18   unsigned long *l = (unsigned long *) 0xfffef088;
19   int i;
20   for(i = 0; i < 16; i++, l++)
21     printk_err("Par%d: 0x%lx\n", i, *l);
22
23   printk_spew("SC520 random fixup ...\n");
24 }
25
26
27
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,
32         .init             = cpu_init,
33         .enable           = 0,
34         .ops_pci          = 0,
35 };
36
37 static struct pci_driver cpu_driver __pci_driver = {
38         .ops = &cpu_operations,
39         .vendor = PCI_VENDOR_ID_AMD,
40         .device = 0x3000
41 };
42
43
44
45 #define BRIDGE_IO_MASK (IORESOURCE_IO | IORESOURCE_MEM)
46
47 static void pci_domain_read_resources(device_t dev)
48 {
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;
55
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;
60 }
61
62 static void ram_resource(device_t dev, unsigned long index,
63         unsigned long basek, unsigned long sizek)
64 {
65         struct resource *resource;
66   printk_spew("%s sizek 0x%x\n", __FUNCTION__, sizek);
67         if (!sizek) {
68                 return;
69         }
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;
75 }
76
77 static void tolm_test(void *gp, struct device *dev, struct resource *new)
78 {
79         struct resource **best_p = gp;
80         struct resource *best;
81         best = *best_p;
82         if (!best || (best->base > new->base)) {
83                 best = new;
84         }
85         *best_p = best;
86 }
87
88 static uint32_t find_pci_tolm(struct bus *bus)
89 {
90         struct resource *min;
91         uint32_t tolm;
92   printk_spew("%s\n", __FUNCTION__);
93         min = 0;
94         search_bus_resources(bus, IORESOURCE_MEM, IORESOURCE_MEM, tolm_test, &min);
95         tolm = 0xffffffffUL;
96         if (min && tolm > min->base) {
97                 tolm = min->base;
98         }
99   printk_spew("%s returns 0x%x\n", __FUNCTION__, tolm);
100         return tolm;
101 }
102
103 static void pci_domain_set_resources(device_t dev)
104 {
105         device_t mc_dev;
106         uint32_t pci_tolm;
107   printk_spew("%s\n", __FUNCTION__);
108         pci_tolm = find_pci_tolm(&dev->link[0]);
109         mc_dev = dev->link[0].children;
110         if (mc_dev) {
111                 unsigned long tomk, tolmk;
112                 //              unsigned char rambits;
113                 // int i;
114                 int idx;
115 #if 0
116                 for(rambits = 0, i = 0; i < sizeof(ramregs)/sizeof(ramregs[0]); i++) {
117                         unsigned char reg;
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.
124                          */
125                         if (reg > rambits)
126                                 rambits = reg;
127                         if (reg < rambits)
128                                 printk_err("ERROR! register 0x%x is not set!\n", 
129                                         ramregs[i]);
130                 }
131                 printk_debug("I would set ram size to 0x%x Kbytes\n", (rambits)*8*1024);
132                 tomk = rambits*8*1024;
133 #endif
134                 tomk = 32 * 1024;
135                 /* Compute the top of Low memory */
136                 tolmk = pci_tolm >> 10;
137                 if (tolmk >= tomk) {
138                         /* The PCI hole does does not overlap the memory.
139                          */
140                         tolmk = tomk;
141                 }
142                 /* Report the memory regions */
143                 idx = 10;
144                 ram_resource(dev, idx++, 0, tolmk);
145         }
146         assign_resources(&dev->link[0]);
147 }
148
149 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max)
150 {
151   printk_spew("%s\n", __FUNCTION__);
152         max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0, 0), 0xff, max);
153         return max;
154 }
155
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,
160         .init             = 0,
161         .scan_bus         = pci_domain_scan_bus,
162 };  
163
164 static void cpu_bus_init(device_t dev)
165 {
166   printk_spew("cpu_bus_init\n");
167 }
168
169 static void cpu_bus_noop(device_t dev)
170 {
171 }
172
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,
178         .scan_bus         = 0,
179 };
180
181 static void enable_dev(struct device *dev)
182 {
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;
187                 pci_set_method(dev);
188         }
189         else if (dev->path.type == DEVICE_PATH_APIC_CLUSTER) {
190                 dev->ops = &cpu_bus_ops;
191         }
192 }
193
194
195 struct chip_operations cpu_amd_sc520_ops = {
196         CHIP_NAME("AMD SC520")
197         .enable_dev = enable_dev, 
198 };