1 #include <console/console.h>
4 #include <device/device.h>
5 #include <device/pci.h>
6 #include <device/pci_ids.h>
11 #include "northbridge.h"
12 #include <cpu/amd/gx2def.h>
13 #include <cpu/x86/msr.h>
14 #include <cpu/x86/cache.h>
16 #define NORTHBRIDGE_FILE "northbridge.c"
20 /* todo: add a resource record. We don't do this here because this may be called when
21 * very little of the platform is actually working.
30 msr = rdmsr(0x20000018);
31 printk_debug("sizeram: %08x:%08x\n", msr.hi, msr.lo);
37 sizem = (1 << ((dimm >> 12)-1)) * 8;
44 sizem += (1 << ((dimm >> 12)-1)) * 8;
46 printk_debug("sizeram: sizem 0x%x\n", sizem);
50 #define CACHE_DISABLE (1<<0)
51 #define WRITE_ALLOCATE (1<<1)
52 #define WRITE_PROTECT (1<<2)
53 #define WRITE_THROUGH (1<<3)
54 #define WRITE_COMBINE (1<<4)
55 #define WRITE_SERIALIZE (1<<5)
57 /* ram has none of this stuff */
58 #define RAM_PROPERTIES (0)
59 #define DEVICE_PROPERTIES (WRITE_SERIALIZE|CACHE_DISABLE)
60 #define ROM_PROPERTIES (WRITE_SERIALIZE|WRITE_THROUGH|CACHE_DISABLE)
63 setup_gx2_cache(int sizem)
66 unsigned long long val;
67 printk_debug("enable_cache: enable for %dm bytes\n", sizem);
68 /* build up the rconf word. */
69 /* the SYSTOP bits 27:8 are actually the top bits from 31:12. Book fails to say that */
71 val = ((unsigned long long) ROM_PROPERTIES) << 56;
72 /* make rom base useful for 1M roms */
73 /* fuctory sets this to a weird value, just go with it. */
74 val |= ((unsigned long long) 0xff800)<<36;
75 /* set the devrp properties */
76 val |= ((unsigned long long) DEVICE_PROPERTIES) << 28;
77 /* sigh. Take our TOM, RIGHT shift 12, since it page-aligned, then LEFT-shift 8 for reg. */
78 /* yank off 8M for frame buffer and 1M for VSA */
84 val |= RAM_PROPERTIES;
87 printk_debug("msr will be set to %x:%x\n", msr.hi, msr.lo);
93 /* we have to do this here. We have not found a nicer way to do it */
100 setup_gx2_cache(sizem);
104 static void optimize_xbus(device_t dev)
106 /* Optimise X-Bus performance */
107 pci_write_config8(dev, 0x40, 0x1e);
108 pci_write_config8(dev, 0x41, 0x52);
109 pci_write_config8(dev, 0x43, 0xc1);
110 pci_write_config8(dev, 0x44, 0x00);
113 static void enable_shadow(device_t dev)
118 static void northbridge_init(device_t dev)
120 printk_debug("northbridge: %s()\n", __FUNCTION__);
127 static struct device_operations northbridge_operations = {
128 .read_resources = pci_dev_read_resources,
129 .set_resources = pci_dev_set_resources,
130 .enable_resources = pci_dev_enable_resources,
131 .init = northbridge_init,
136 static struct pci_driver northbridge_driver __pci_driver = {
137 .ops = &northbridge_operations,
138 .vendor = PCI_VENDOR_ID_CYRIX,
139 .device = PCI_DEVICE_ID_CYRIX_PCI_MASTER,
144 #define BRIDGE_IO_MASK (IORESOURCE_IO | IORESOURCE_MEM)
146 static void pci_domain_read_resources(device_t dev)
148 struct resource *resource;
150 printk_spew("%s:%s()\n", NORTHBRIDGE_FILE, __FUNCTION__);
152 /* Initialize the system wide io space constraints */
153 resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0,0));
154 resource->limit = 0xffffUL;
155 resource->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED;
157 /* Initialize the system wide memory resources constraints */
158 resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1,0));
159 resource->limit = 0xffffffffULL;
160 resource->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED;
163 static void ram_resource(device_t dev, unsigned long index,
164 unsigned long basek, unsigned long sizek)
166 struct resource *resource;
171 resource = new_resource(dev, index);
172 resource->base = ((resource_t)basek) << 10;
173 resource->size = ((resource_t)sizek) << 10;
174 resource->flags = IORESOURCE_MEM | IORESOURCE_CACHEABLE | \
175 IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
178 static void tolm_test(void *gp, struct device *dev, struct resource *new)
180 struct resource **best_p = gp;
181 struct resource *best;
183 if (!best || (best->base > new->base)) {
189 static uint32_t find_pci_tolm(struct bus *bus)
191 struct resource *min;
194 search_bus_resources(bus, IORESOURCE_MEM, IORESOURCE_MEM, tolm_test, &min);
196 if (min && tolm > min->base) {
202 #define FRAMEBUFFERK 4096
204 static void pci_domain_set_resources(device_t dev)
209 pci_tolm = find_pci_tolm(&dev->link[0]);
210 mc_dev = dev->link[0].children;
212 unsigned int tomk, tolmk;
213 unsigned int ramreg = 0;
215 unsigned int *bcdramtop = (unsigned int *)(GX_BASE + BC_DRAM_TOP);
216 unsigned int *mcgbaseadd = (unsigned int *)(GX_BASE + MC_GBASE_ADD);
218 for(i=0; i<0x20; i+= 0x10) {
219 unsigned int *mcreg = (unsigned int *)(GX_BASE + MC_BANK_CFG);
220 unsigned int mem_config = *mcreg;
222 if (((mem_config & (DIMM_PG_SZ << i)) >> (4 + i)) == 7)
224 ramreg += 1 << (((mem_config & (DIMM_SZ << i)) >> (i + 8)) + 2);
229 /* Sort out the framebuffer size */
230 tomk -= FRAMEBUFFERK;
231 *bcdramtop = ((tomk << 10) - 1);
232 *mcgbaseadd = (tomk >> 9);
234 printk_debug("BC_DRAM_TOP = 0x%08x\n", *bcdramtop);
235 printk_debug("MC_GBASE_ADD = 0x%08x\n", *mcgbaseadd);
237 printk_debug("I would set ram size to %d Mbytes\n", (tomk >> 10));
239 /* Compute the top of Low memory */
240 tolmk = pci_tolm >> 10;
242 /* The PCI hole does does not overlap the memory.
246 /* Report the memory regions */
248 ram_resource(dev, idx++, 0, tolmk);
250 assign_resources(&dev->link[0]);
254 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max)
256 max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0, 0), 0xff, max);
260 static struct device_operations pci_domain_ops = {
261 .read_resources = pci_domain_read_resources,
262 .set_resources = pci_domain_set_resources,
263 .enable_resources = enable_childrens_resources,
265 .scan_bus = pci_domain_scan_bus,
268 static void cpu_bus_init(device_t dev)
270 initialize_cpus(&dev->link[0]);
273 static void cpu_bus_noop(device_t dev)
277 static struct device_operations cpu_bus_ops = {
278 .read_resources = cpu_bus_noop,
279 .set_resources = cpu_bus_noop,
280 .enable_resources = cpu_bus_noop,
281 .init = cpu_bus_init,
285 static void enable_dev(struct device *dev)
287 printk_debug("gx2 north: enable_dev\n");
288 /* Set the operations if it is a special bus type */
289 if (dev->path.type == DEVICE_PATH_PCI_DOMAIN) {
290 printk_debug("DEVICE_PATH_PCI_DOMAIN\n");
292 dev->ops = &pci_domain_ops;
295 else if (dev->path.type == DEVICE_PATH_APIC_CLUSTER) {
296 printk_debug("DEVICE_PATH_APIC_CLUSTER\n");
297 dev->ops = &cpu_bus_ops;
301 struct chip_operations northbridge_amd_gx2_ops = {
302 CHIP_NAME("AMD GX2 Northbridge")
303 .enable_dev = enable_dev,