SI Class code check
[coreboot.git] / src / mainboard / tyan / s4882 / mainboard.c
1 #include <console/console.h>
2 #include <device/device.h>
3 #include <device/pci.h>
4 #include <device/pci_ids.h>
5 #include <device/pci_ops.h>
6 #include "chip.h"
7
8 #undef DEBUG
9 #define DEBUG 0
10 #if DEBUG 
11
12 static void print_pci_regs(struct device *dev)
13 {
14       uint8_t byte;
15       int i;
16
17       for(i=0;i<256;i++) {
18              byte = pci_read_config8(dev, i);
19    
20              if((i & 0xf)==0) printk_debug("\n%02x:",i);
21              printk_debug(" %02x",byte);
22       }
23       printk_debug("\n");
24
25 }
26 static void print_mem(void)
27 {
28         unsigned int i;
29         unsigned int start = 0xfffff000;
30         for(i=start;i<0xffffffff;i++) {
31              if((i & 0xf)==0) printk_debug("\n %08x:",i);
32              printk_debug(" %02x ",(unsigned char)*((unsigned char *)i));
33              }
34         printk_debug(" %02x \n",(unsigned char)*((unsigned char *)i));
35
36  }
37 static void print_pci_regs_all(void)
38 {
39         struct device *dev;
40         unsigned char i,j,k;
41
42         for(i=0;i<=15;i++) {
43                 for(j=0;j<=0x1f;j++) {
44                         for (k=0;k<=6;k++){
45                                 dev = dev_find_slot(i, PCI_DEVFN(j, k));
46                                 if(!dev) {
47                                         continue;
48                                 }
49                                 if(!dev->enabled) {
50                                         continue;
51                                 }
52                                 printk_debug("\n%02x:%02x:%02x aka %s",i,j,k, dev_path(dev));
53                                 print_pci_regs(dev);
54                         }
55                 }
56         }
57
58 }
59  
60 static void debug_init(device_t dev)
61 {
62         unsigned bus;
63         unsigned devfn;
64
65 //      print_pci_regs_all();
66
67         print_mem();
68 #if 0
69         msr_t msr;
70         unsigned index;
71         unsigned eax, ebx, ecx, edx;
72         index = 0x80000007;
73         printk_debug("calling cpuid 0x%08x\n", index);
74         asm volatile(
75                 "cpuid"
76                 : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
77                 : "a" (index)
78                 );
79         printk_debug("cpuid[%08x]: %08x %08x %08x %08x\n",
80                 index, eax, ebx, ecx, edx);
81         if (edx & (3 << 1)) {
82                 index = 0xC0010042;
83                 printk_debug("Reading msr: 0x%08x\n", index);
84                 msr = rdmsr(index);
85                 printk_debug("msr[0x%08x]: 0x%08x%08x\n",
86                         index, msr.hi, msr.hi);
87         }
88 #endif
89 }
90
91 static void debug_noop(device_t dummy)
92 {
93 }
94
95 static struct device_operations debug_operations = {
96         .read_resources   = debug_noop,
97         .set_resources    = debug_noop,
98         .enable_resources = debug_noop,
99         .init             = debug_init,
100 };
101
102 static unsigned int scan_root_bus(device_t root, unsigned int max)
103 {
104         struct device_path path;
105         device_t debug;
106         max = root_dev_scan_bus(root, max);
107         path.type = DEVICE_PATH_PNP;
108         path.u.pnp.port   = 0;
109         path.u.pnp.device = 0;
110         debug = alloc_dev(&root->link[1], &path);
111         debug->ops = &debug_operations;
112         return max;
113 }
114
115
116 static void mainboard_init(device_t dev)
117 {       
118         root_dev_init(dev);
119         // Do sth
120 }
121
122 static struct device_operations mainboard_operations = {
123         .read_resources   = root_dev_read_resources,
124         .set_resources    = root_dev_set_resources,
125         .enable_resources = root_dev_enable_resources,
126         .init             = mainboard_init,
127         .scan_bus         = scan_root_bus,
128 };
129
130 static void enable_dev(struct device *dev)
131 {
132         dev_root.ops = &mainboard_operations;
133 }
134 #endif
135
136 struct chip_operations mainboard_tyan_s4882_ops = {
137         CHIP_NAME("Tyan s4882 mainboard")
138 #if DEBUG
139         .enable_dev = enable_dev, 
140 #endif
141 };