- First stab at getting the ppc ports building and working.
[coreboot.git] / src / northbridge / amd / amdk8 / northbridge.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 <cpu/cpu.h>
12 #include "chip.h"
13 #include "root_complex/chip.h"
14 #include "northbridge.h"
15 #include "amdk8.h"
16
17 #define FX_DEVS 8
18 static device_t __f0_dev[FX_DEVS];
19 static device_t __f1_dev[FX_DEVS];
20
21 #if 0
22 static void debug_fx_devs(void)
23 {
24         int i;
25         for(i = 0; i < FX_DEVS; i++) {
26                 device_t dev;
27                 dev = __f0_dev[i];
28                 if (dev) {
29                         printk_debug("__f0_dev[%d]: %s bus: %p\n",
30                                 i, dev_path(dev), dev->bus);
31                 }
32                 dev = __f1_dev[i];
33                 if (dev) {
34                         printk_debug("__f1_dev[%d]: %s bus: %p\n",
35                                 i, dev_path(dev), dev->bus);
36                 }
37         }
38 }
39 #endif
40
41 static void get_fx_devs(void)
42 {
43         int i;
44         if (__f1_dev[0]) {
45                 return;
46         }
47         for(i = 0; i < FX_DEVS; i++) {
48                 __f0_dev[i] = dev_find_slot(0, PCI_DEVFN(0x18 + i, 0));
49                 __f1_dev[i] = dev_find_slot(0, PCI_DEVFN(0x18 + i, 1));
50         }
51         if (!__f1_dev[0]) {
52                 die("Cannot find 0:0x18.1\n");
53         }
54 }
55
56 static uint32_t f1_read_config32(unsigned reg)
57 {
58         get_fx_devs();
59         return pci_read_config32(__f1_dev[0], reg);
60 }
61
62 static void f1_write_config32(unsigned reg, uint32_t value)
63 {
64         int i;
65         get_fx_devs();
66         for(i = 0; i < FX_DEVS; i++) {
67                 device_t dev;
68                 dev = __f1_dev[i];
69                 if (dev && dev->enabled) {
70                         pci_write_config32(dev, reg, value);
71                 }
72         }
73 }
74
75 static unsigned int amdk8_nodeid(device_t dev)
76 {
77         return (dev->path.u.pci.devfn >> 3) - 0x18;
78 }
79
80 static unsigned int amdk8_scan_chains(device_t dev, unsigned int max)
81 {
82         unsigned nodeid;
83         unsigned link;
84         nodeid = amdk8_nodeid(dev);
85 #if 0
86         printk_debug("%s amdk8_scan_chains max: %d starting...\n", 
87                 dev_path(dev), max);
88 #endif
89         for(link = 0; link < dev->links; link++) {
90                 uint32_t link_type;
91                 uint32_t busses, config_busses;
92                 unsigned free_reg, config_reg;
93                 dev->link[link].cap = 0x80 + (link *0x20);
94                 do {
95                         link_type = pci_read_config32(dev, dev->link[link].cap + 0x18);
96                 } while(link_type & ConnectionPending);
97                 if (!(link_type & LinkConnected)) {
98                         continue;
99                 }
100                 do {
101                         link_type = pci_read_config32(dev, dev->link[link].cap + 0x18);
102                 } while(!(link_type & InitComplete));
103                 if (!(link_type & NonCoherent)) {
104                         continue;
105                 }
106                 /* See if there is an available configuration space mapping register in function 1. */
107                 free_reg = 0;
108                 for(config_reg = 0xe0; config_reg <= 0xec; config_reg += 4) {
109                         uint32_t config;
110                         config = f1_read_config32(config_reg);
111                         if (!free_reg && ((config & 3) == 0)) {
112                                 free_reg = config_reg;
113                                 continue;
114                         }
115                         if (((config & 3) == 3) && 
116                                 (((config >> 4) & 7) == nodeid) &&
117                                 (((config >> 8) & 3) == link)) {
118                                 break;
119                         }
120                 }
121                 if (free_reg && (config_reg > 0xec)) {
122                         config_reg = free_reg;
123                 }
124                 /* If we can't find an available configuration space mapping register skip this bus */
125                 if (config_reg > 0xec) {
126                         continue;
127                 }
128
129                 /* Set up the primary, secondary and subordinate bus numbers.  We have
130                  * no idea how many busses are behind this bridge yet, so we set the subordinate
131                  * bus number to 0xff for the moment.
132                  */
133                 dev->link[link].secondary = ++max;
134                 dev->link[link].subordinate = 0xff;
135
136                 /* Read the existing primary/secondary/subordinate bus
137                  * number configuration.
138                  */
139                 busses = pci_read_config32(dev, dev->link[link].cap + 0x14);
140                 config_busses = f1_read_config32(config_reg);
141                 
142                 /* Configure the bus numbers for this bridge: the configuration
143                  * transactions will not be propagates by the bridge if it is not
144                  * correctly configured
145                  */
146                 busses &= 0xff000000;
147                 busses |= (((unsigned int)(dev->bus->secondary) << 0) |
148                         ((unsigned int)(dev->link[link].secondary) << 8) |
149                         ((unsigned int)(dev->link[link].subordinate) << 16));
150                 pci_write_config32(dev, dev->link[link].cap + 0x14, busses);
151
152                 config_busses &= 0x000fc88;
153                 config_busses |= 
154                         (3 << 0) |  /* rw enable, no device compare */
155                         (( nodeid & 7) << 4) | 
156                         (( link & 3 ) << 8) |  
157                         ((dev->link[link].secondary) << 16) |
158                         ((dev->link[link].subordinate) << 24);
159                 f1_write_config32(config_reg, config_busses);
160
161 #if 0
162                 printk_debug("%s Hyper transport scan link: %d max: %d\n", 
163                         dev_path(dev), link, max);
164 #endif          
165                 /* Now we can scan all of the subordinate busses i.e. the chain on the hypertranport link */
166                 max = hypertransport_scan_chain(&dev->link[link], max);
167
168 #if 0
169                 printk_debug("%s Hyper transport scan link: %d new max: %d\n",
170                         dev_path(dev), link, max);
171 #endif          
172
173                 /* We know the number of busses behind this bridge.  Set the subordinate
174                  * bus number to it's real value
175                  */
176                 dev->link[link].subordinate = max;
177                 busses = (busses & 0xff00ffff) |
178                         ((unsigned int) (dev->link[link].subordinate) << 16);
179                 pci_write_config32(dev, dev->link[link].cap + 0x14, busses);
180
181                 config_busses = (config_busses & 0x00ffffff) | (dev->link[link].subordinate << 24);
182                 f1_write_config32(config_reg, config_busses);
183 #if 0
184                 printk_debug("%s Hypertransport scan link: %d done\n",
185                         dev_path(dev), link);
186 #endif          
187         }
188 #if 0
189         printk_debug("%s amdk8_scan_chains max: %d done\n", 
190                 dev_path(dev), max);
191 #endif
192         return max;
193 }
194
195 static int reg_useable(unsigned reg, 
196         device_t goal_dev, unsigned goal_nodeid, unsigned goal_link)
197 {
198         struct resource *res;
199         unsigned nodeid, link;
200         int result;
201         res = 0;
202         for(nodeid = 0; !res && (nodeid < 8); nodeid++) {
203                 device_t dev;
204                 dev = __f0_dev[nodeid];
205                 for(link = 0; !res && (link < 3); link++) {
206                         res = probe_resource(dev, 0x100 + (reg | link));
207                 }
208         }
209         result = 2;
210         if (res) {
211                 result = 0;
212                 if (    (goal_link == (link - 1)) && 
213                         (goal_nodeid == (nodeid - 1)) &&
214                         (res->flags <= 1)) {
215                         result = 1;
216                 }
217         }
218 #if 0
219         printk_debug("reg: %02x result: %d gnodeid: %u glink: %u nodeid: %u link: %u\n",
220                 reg, result, 
221                 goal_nodeid, goal_link, 
222                 nodeid, link);
223 #endif
224         return result;
225 }
226
227
228 static struct resource *amdk8_find_iopair(device_t dev, unsigned nodeid, unsigned link)
229 {
230         struct resource *resource;
231         unsigned free_reg, reg;
232         resource = 0;
233         free_reg = 0;
234         for(reg = 0xc0; reg <= 0xd8; reg += 0x8) {
235                 int result;
236                 result = reg_useable(reg, dev, nodeid, link);
237                 if (result == 1) {
238                         /* I have been allocated this one */
239                         break;
240                 }
241                 else if (result > 1) {
242                         /* I have a free register pair */
243                         free_reg = reg;
244                 }
245         }
246         if (reg > 0xd8) {
247                 reg = free_reg;
248         }
249         if (reg > 0) {
250                 resource = new_resource(dev, 0x100 + (reg | link));
251         }
252         return resource;
253 }
254
255 static struct resource *amdk8_find_mempair(device_t dev, unsigned nodeid, unsigned link)
256 {
257         struct resource *resource;
258         unsigned free_reg, reg;
259         resource = 0;
260         free_reg = 0;
261         for(reg = 0x80; reg <= 0xb8; reg += 0x8) {
262                 int result;
263                 result = reg_useable(reg, dev, nodeid, link);
264                 if (result == 1) {
265                         /* I have been allocated this one */
266                         break;
267                 }
268                 else if (result > 1) {
269                         /* I have a free register pair */
270                         free_reg = reg;
271                 }
272         }
273         if (reg > 0xb8) {
274                 reg = free_reg;
275         }
276         if (reg > 0) {
277                 resource = new_resource(dev, 0x100 + (reg | link));
278         }
279         return resource;
280 }
281 static void amdk8_link_read_bases(device_t dev, unsigned nodeid, unsigned link)
282 {
283         struct resource *resource;
284         
285         /* Initialize the io space constraints on the current bus */
286         resource =  amdk8_find_iopair(dev, nodeid, link);
287         if (resource) {
288                 resource->base  = 0;
289                 resource->size  = 0;
290                 resource->align = log2(HT_IO_HOST_ALIGN);
291                 resource->gran  = log2(HT_IO_HOST_ALIGN);
292                 resource->limit = 0xffffUL;
293                 resource->flags = IORESOURCE_IO;
294                 compute_allocate_resource(&dev->link[link], resource, 
295                         IORESOURCE_IO, IORESOURCE_IO);
296         }
297
298         /* Initialize the prefetchable memory constraints on the current bus */
299         resource = amdk8_find_mempair(dev, nodeid, link);
300         if (resource) {
301                 resource->base  = 0;
302                 resource->size  = 0;
303                 resource->align = log2(HT_MEM_HOST_ALIGN);
304                 resource->gran  = log2(HT_MEM_HOST_ALIGN);
305                 resource->limit = 0xffffffffffULL;
306                 resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
307                 compute_allocate_resource(&dev->link[link], resource, 
308                         IORESOURCE_MEM | IORESOURCE_PREFETCH, 
309                         IORESOURCE_MEM | IORESOURCE_PREFETCH);
310         }
311
312         /* Initialize the memory constraints on the current bus */
313         resource = amdk8_find_mempair(dev, nodeid, link);
314         if (resource) {
315                 resource->base  = 0;
316                 resource->size  = 0;
317                 resource->align = log2(HT_MEM_HOST_ALIGN);
318                 resource->gran  = log2(HT_MEM_HOST_ALIGN);
319                 resource->limit = 0xffffffffffULL;
320                 resource->flags = IORESOURCE_MEM;
321                 compute_allocate_resource(&dev->link[link], resource, 
322                         IORESOURCE_MEM | IORESOURCE_PREFETCH, 
323                         IORESOURCE_MEM);
324         }
325 }
326
327 static void amdk8_read_resources(device_t dev)
328 {
329         unsigned nodeid, link;
330         nodeid = amdk8_nodeid(dev);
331         for(link = 0; link < dev->links; link++) {
332                 if (dev->link[link].children) {
333                         amdk8_link_read_bases(dev, nodeid, link);
334                 }
335         }
336 }
337
338 static void amdk8_set_resource(device_t dev, struct resource *resource, unsigned nodeid)
339 {
340         resource_t rbase, rend;
341         unsigned reg, link;
342         char buf[50];
343
344         /* Make certain the resource has actually been set */
345         if (!(resource->flags & IORESOURCE_ASSIGNED)) {
346                 return;
347         }
348
349         /* If I have already stored this resource don't worry about it */
350         if (resource->flags & IORESOURCE_STORED) {
351                 return;
352         }
353         
354         /* Only handle PCI memory and IO resources */
355         if (!(resource->flags & (IORESOURCE_MEM | IORESOURCE_IO)))
356                 return;
357
358         /* Ensure I am actually looking at a resource of function 1 */
359         if (resource->index < 0x100) {
360                 return;
361         }
362         /* Get the base address */
363         rbase = resource->base;
364         
365         /* Get the limit (rounded up) */
366         rend  = resource_end(resource);
367
368         /* Get the register and link */
369         reg  = resource->index & 0xfc;
370         link = resource->index & 3;
371
372         if (resource->flags & IORESOURCE_IO) {
373                 uint32_t base, limit;
374                 compute_allocate_resource(&dev->link[link], resource,
375                         IORESOURCE_IO, IORESOURCE_IO);
376                 base  = f1_read_config32(reg);
377                 limit = f1_read_config32(reg + 0x4);
378                 base  &= 0xfe000fcc;
379                 base  |= rbase  & 0x01fff000;
380                 base  |= 3;
381                 limit &= 0xfe000fc8;
382                 limit |= rend & 0x01fff000;
383                 limit |= (link & 3) << 4;
384                 limit |= (nodeid & 7);
385
386                 if (dev->link[link].bridge_ctrl & PCI_BRIDGE_CTL_VGA) {
387                         base |= PCI_IO_BASE_VGA_EN;
388                 }
389                 if (dev->link[link].bridge_ctrl & PCI_BRIDGE_CTL_NO_ISA) {
390                         base |= PCI_IO_BASE_NO_ISA;
391                 }
392                 
393                 f1_write_config32(reg + 0x4, limit);
394                 f1_write_config32(reg, base);
395         }
396         else if (resource->flags & IORESOURCE_MEM) {
397                 uint32_t base, limit;
398                 compute_allocate_resource(&dev->link[link], resource,
399                         IORESOURCE_MEM | IORESOURCE_PREFETCH,
400                         resource->flags & (IORESOURCE_MEM | IORESOURCE_PREFETCH));
401                 base  = f1_read_config32(reg);
402                 limit = f1_read_config32(reg + 0x4);
403                 base  &= 0x000000f0;
404                 base  |= (rbase >> 8) & 0xffffff00;
405                 base  |= 3;
406                 limit &= 0x00000048;
407                 limit |= (rend >> 8) & 0xffffff00;
408                 limit |= (link & 3) << 4;
409                 limit |= (nodeid & 7);
410                 f1_write_config32(reg + 0x4, limit);
411                 f1_write_config32(reg, base);
412         }
413         resource->flags |= IORESOURCE_STORED;
414         sprintf(buf, " <node %d link %d>",
415                 nodeid, link);
416         report_resource_stored(dev, resource, buf);
417 }
418
419 static void amdk8_set_resources(device_t dev)
420 {
421         unsigned nodeid, link;
422         int i;
423
424         /* Find the nodeid */
425         nodeid = amdk8_nodeid(dev);     
426
427         /* Set each resource we have found */
428         for(i = 0; i < dev->resources; i++) {
429                 amdk8_set_resource(dev, &dev->resource[i], nodeid);
430         }
431         
432         for(link = 0; link < dev->links; link++) {
433                 struct bus *bus;
434                 bus = &dev->link[link];
435                 if (bus->children) {
436                         assign_resources(bus);
437                 }
438         }
439 }
440
441 static void amdk8_enable_resources(device_t dev)
442 {
443         pci_dev_enable_resources(dev);
444         enable_childrens_resources(dev);
445 }
446
447 static void mcf0_control_init(struct device *dev)
448 {
449         uint32_t cmd;
450
451 #if 0   
452         printk_debug("NB: Function 0 Misc Control.. ");
453 #endif
454 #if 1
455         /* improve latency and bandwith on HT */
456         cmd = pci_read_config32(dev, 0x68);
457         cmd &= 0xffff80ff;
458         cmd |= 0x00004800;
459         pci_write_config32(dev, 0x68, cmd );
460 #endif
461
462 #if 0   
463         /* over drive the ht port to 1000 Mhz */
464         cmd = pci_read_config32(dev, 0xa8);
465         cmd &= 0xfffff0ff;
466         cmd |= 0x00000600;
467         pci_write_config32(dev, 0xdc, cmd );
468 #endif  
469 #if 0
470         printk_debug("done.\n");
471 #endif
472 }
473
474 static struct device_operations northbridge_operations = {
475         .read_resources   = amdk8_read_resources,
476         .set_resources    = amdk8_set_resources,
477         .enable_resources = amdk8_enable_resources,
478         .init             = mcf0_control_init,
479         .scan_bus         = amdk8_scan_chains,
480         .enable           = 0,
481         .ops_pci          = 0,
482 };
483
484
485 static struct pci_driver mcf0_driver __pci_driver = {
486         .ops    = &northbridge_operations,
487         .vendor = PCI_VENDOR_ID_AMD,
488         .device = 0x1100,
489 };
490
491 #if CONFIG_CHIP_NAME == 1
492
493 struct chip_operations northbridge_amd_amdk8_ops = {
494         CHIP_NAME("AMD K8 Northbridge")
495         .enable_dev = 0,
496 };
497
498 #endif
499
500 static void pci_domain_read_resources(device_t dev)
501 {
502         struct resource *resource;
503         unsigned reg;
504
505         /* Find the already assigned resource pairs */
506         get_fx_devs();
507         for(reg = 0x80; reg <= 0xd8; reg+= 0x08) {
508                 uint32_t base, limit;
509                 base  = f1_read_config32(reg);
510                 limit = f1_read_config32(reg + 0x04);
511                 /* Is this register allocated? */
512                 if ((base & 3) != 0) {
513                         unsigned nodeid, link;
514                         device_t dev;
515                         nodeid = limit & 7;
516                         link   = (limit >> 4) & 3;
517                         dev = __f0_dev[nodeid];
518                         if (dev) {
519                                 /* Reserve the resource  */
520                                 struct resource *resource;
521                                 resource = new_resource(dev, 0x100 + (reg | link));
522                                 if (resource) {
523                                         resource->flags = 1;
524                                 }
525                         }
526                 }
527         }
528
529         /* Initialize the system wide io space constraints */
530         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0));
531         resource->base  = 0x400;
532         resource->limit = 0xffffUL;
533         resource->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED;
534         
535         /* Initialize the system wide memory resources constraints */
536         resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0));
537         resource->limit = 0xfcffffffffULL;
538         resource->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED;
539 }
540
541 static void ram_resource(device_t dev, unsigned long index, 
542         unsigned long basek, unsigned long sizek)
543 {
544         struct resource *resource;
545
546         if (!sizek) {
547                 return;
548         }
549         resource = new_resource(dev, index);
550         resource->base  = ((resource_t)basek) << 10;
551         resource->size  = ((resource_t)sizek) << 10;
552         resource->flags =  IORESOURCE_MEM | IORESOURCE_CACHEABLE | \
553                 IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
554 }
555
556 static void tolm_test(void *gp, struct device *dev, struct resource *new)
557 {
558         struct resource **best_p = gp;
559         struct resource *best;
560         best = *best_p;
561         if (!best || (best->base > new->base)) {
562                 best = new;
563         }
564         *best_p = best;
565 }
566
567 static uint32_t find_pci_tolm(struct bus *bus)
568 {
569         struct resource *min;
570         uint32_t tolm;
571         min = 0;
572         search_bus_resources(bus, IORESOURCE_MEM, IORESOURCE_MEM, tolm_test, &min);
573         tolm = 0xffffffffUL;
574         if (min && tolm > min->base) {
575                 tolm = min->base;
576         }
577         return tolm;
578 }
579
580 static void pci_domain_set_resources(device_t dev)
581 {
582         unsigned long mmio_basek;
583         uint32_t pci_tolm;
584         int i, idx;
585
586         pci_tolm = find_pci_tolm(&dev->link[0]);
587
588 #warning "FIXME handle interleaved nodes"
589         mmio_basek = pci_tolm >> 10;
590         /* Round mmio_basek to something the processor can support */
591         mmio_basek &= ~((1 << 6) -1);
592
593 #if 1
594 #warning "FIXME improve mtrr.c so we don't use up all of the mtrrs with a 64M MMIO hole"
595         /* Round the mmio hold to 64M */
596         mmio_basek &= ~((64*1024) - 1);
597 #endif
598
599         idx = 10;
600         for(i = 0; i < 8; i++) {
601                 uint32_t base, limit;
602                 unsigned basek, limitk, sizek;
603                 base  = f1_read_config32(0x40 + (i << 3));
604                 limit = f1_read_config32(0x44 + (i << 3));
605                 if ((base & ((1<<1)|(1<<0))) != ((1<<1)|(1<<0))) {
606                         continue;
607                 }
608                 basek = (base & 0xffff0000) >> 2;
609                 limitk = ((limit + 0x00010000) & 0xffff0000) >> 2;
610                 sizek = limitk - basek;
611
612                 /* see if we need a hole from 0xa0000 to 0xbffff */
613                 if ((basek < ((8*64)+(8*16))) && (sizek > ((8*64)+(16*16)))) {
614                         ram_resource(dev, idx++, basek, ((8*64)+(8*16)) - basek);
615                         basek = (8*64)+(16*16);
616                         sizek = limitk - ((8*64)+(16*16));
617                         
618                 }
619
620                 
621                 /* See if I need to split the region to accomodate pci memory space */
622                 if ((basek < mmio_basek) && (limitk > mmio_basek)) {
623                         if (basek < mmio_basek) {
624                                 unsigned pre_sizek;
625                                 pre_sizek = mmio_basek - basek;
626                                 ram_resource(dev, idx++, basek, pre_sizek);
627                                 sizek -= pre_sizek;
628                                 basek = mmio_basek;
629                         }
630                         if ((basek + sizek) <= 4*1024*1024) {
631                                 sizek = 0;
632                         }
633                         else {
634                                 basek = 4*1024*1024;
635                                 sizek -= (4*1024*1024 - mmio_basek);
636                         }
637                 }
638                 ram_resource(dev, idx++, basek, sizek);
639         }
640         assign_resources(&dev->link[0]);
641 }
642
643 static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max)
644 {
645         unsigned reg;
646         /* Unmap all of the HT chains */
647         for(reg = 0xe0; reg <= 0xec; reg += 4) {
648                 f1_write_config32(reg, 0);
649         }
650         max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0x18, 0), 0xff, max);
651         return max;
652 }
653
654 static struct device_operations pci_domain_ops = {
655         .read_resources   = pci_domain_read_resources,
656         .set_resources    = pci_domain_set_resources,
657         .enable_resources = enable_childrens_resources,
658         .init             = 0,
659         .scan_bus         = pci_domain_scan_bus,
660         .ops_pci_bus      = &pci_cf8_conf1,
661 };
662
663 static unsigned int cpu_bus_scan(device_t dev, unsigned int max)
664 {
665         struct bus *cpu_bus;
666         int i;
667
668         /* Find which cpus are present */
669         cpu_bus = &dev->link[0];
670         for(i = 0; i < 8; i++) {
671                 device_t dev, cpu;
672                 struct device_path cpu_path;
673
674                 /* Find the cpu's memory controller */
675                 dev = dev_find_slot(0, PCI_DEVFN(0x18 + i, 0));
676
677                 /* Build the cpu device path */
678                 cpu_path.type = DEVICE_PATH_APIC;
679                 cpu_path.u.apic.apic_id = i;
680
681                 /* See if I can find the cpu */
682                 cpu = find_dev_path(cpu_bus, &cpu_path);
683
684                 /* Enable the cpu if I have the processor */
685                 if (dev && dev->enabled) {
686                         if (!cpu) {
687                                 cpu = alloc_dev(cpu_bus, &cpu_path);
688                         }
689                         if (cpu) {
690                                 cpu->enabled = 1;
691                         }
692                 }
693                 
694                 /* Disable the cpu if I don't have the processor */
695                 if (cpu && (!dev || !dev->enabled)) {
696                         cpu->enabled = 0;
697                 }
698                 
699                 /* Report what I have done */
700                 if (cpu) {
701                         printk_debug("CPU: %s %s\n",
702                                 dev_path(cpu), cpu->enabled?"enabled":"disabled");
703                 }
704         }
705         return max;
706 }
707
708 static void cpu_bus_init(device_t dev)
709 {
710         initialize_cpus(&dev->link[0]);
711 }
712
713 static void cpu_bus_noop(device_t dev) 
714 {
715 }
716
717 static struct device_operations cpu_bus_ops = {
718         .read_resources   = cpu_bus_noop,
719         .set_resources    = cpu_bus_noop,
720         .enable_resources = cpu_bus_noop,
721         .init             = cpu_bus_init,       
722         .scan_bus         = cpu_bus_scan,
723 };
724
725 static void root_complex_enable_dev(struct device *dev)
726 {
727         /* Set the operations if it is a special bus type */
728         if (dev->path.type == DEVICE_PATH_PCI_DOMAIN) {
729                 dev->ops = &pci_domain_ops;
730         }
731         else if (dev->path.type == DEVICE_PATH_APIC_CLUSTER) {
732                 dev->ops = &cpu_bus_ops;
733         }
734 }
735
736 struct chip_operations northbridge_amd_amdk8_root_complex_ops = {
737         CHIP_NAME("AMD K8 Root Complex")
738         .enable_dev = root_complex_enable_dev,
739 };