1 #include <console/console.h>
2 #include <device/device.h>
3 #include <device/smbus.h>
4 #include <device/pci.h>
5 #include <device/pci_ids.h>
6 #include <device/pci_ops.h>
7 #include <cpu/x86/msr.h>
10 static void print_pci_regs(struct device *dev)
16 byte = pci_read_config8(dev, i);
18 if((i & 0xf)==0) printk_debug("\n%02x:",i);
19 printk_debug(" %02x",byte);
24 static void print_mem(void)
27 unsigned int start = 0xfffff000;
28 for(i=start;i<0xffffffff;i++) {
29 if((i & 0xf)==0) printk_debug("\n %08x:",i);
30 printk_debug(" %02x",(unsigned char)*((unsigned char *)i));
32 printk_debug(" %02x\n",(unsigned char)*((unsigned char *)i));
35 static void print_pci_regs_all(void)
38 unsigned bus, device, function;
40 for(bus=0; bus<256; bus++) {
41 for(device=0; device<=0x1f; device++) {
42 for (function=0; function<=7; function++){
44 devfn = PCI_DEVFN(device, function);
45 dev = dev_find_slot(bus, devfn);
52 printk_debug("\n%02x:%02x:%02x aka %s",
53 bus, device, function, dev_path(dev));
60 static void print_cpuid()
64 unsigned eax, ebx, ecx, edx;
66 printk_debug("calling cpuid 0x%08x\n", index);
69 : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
72 printk_debug("cpuid[%08x]: %08x %08x %08x %08x\n",
73 index, eax, ebx, ecx, edx);
76 printk_debug("Reading msr: 0x%08x\n", index);
78 printk_debug("msr[0x%08x]: 0x%08x%08x\n",
79 index, msr.hi, msr.lo);
83 static void print_smbus_regs(struct device *dev)
86 printk_debug("smbus: %s[%d]->", dev_path(dev->bus->dev), dev->bus->link);
87 printk_debug("%s", dev_path(dev));
88 for(j = 0; j < 256; j++) {
91 status = smbus_read_byte(dev, j);
93 // printk_debug("bad device status= %08x\r\n", status);
97 printk_debug("\r\n%02x: ", j);
100 printk_debug("%02x ", byte);
102 printk_debug("\r\n");
105 static void print_smbus_regs_all(struct device *dev)
107 struct device *child;
109 if (dev->enabled && dev->path.type == DEVICE_PATH_I2C)
111 // Here don't need to call smbus_set_link, because we scan it from top to down
112 if( dev->bus->dev->path.type == DEVICE_PATH_I2C) { // it's under i2c MUX so set mux at first
113 if(ops_smbus_bus(get_pbus_smbus(dev->bus->dev))) {
114 if(dev->bus->dev->ops && dev->bus->dev->ops->set_link)
115 dev->bus->dev->ops->set_link(dev->bus->dev, dev->bus->link);
119 if(ops_smbus_bus(get_pbus_smbus(dev))) print_smbus_regs(dev);
122 for(i=0; i< dev->links; i++) {
123 for (child = dev->link[i].children; child; child = child->sibling) {
124 print_smbus_regs_all(child);
128 static void print_msr_dualcore(void)
132 unsigned eax, ebx, ecx, edx;
134 printk_debug("calling cpuid 0x%08x\n", index);
137 : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
140 printk_debug("cpuid[%08x]: %08x %08x %08x %08x\n",
141 index, eax, ebx, ecx, edx);
143 printk_debug("core number %d\n", ecx & 0xff);
146 printk_debug("Reading msr: 0x%08x\n", index);
148 printk_debug("msr[0x%08x]: 0x%08x%08x bit 54 is %d\n",
149 index, msr.hi, msr.lo, (msr.hi>> (54-32)) & 1);
151 msr.hi |= (1<<(54-32));
155 printk_debug("msr[0x%08x]: 0x%08x%08x\n",
156 index, msr.hi, msr.lo);
161 static void print_cache_size(void)
164 unsigned int n, eax, ebx, ecx, edx;
167 printk_debug("calling cpuid 0x%08x\n", index);
170 : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
175 if (n >= 0x80000005) {
177 printk_debug("calling cpuid 0x%08x\n", index);
180 : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
183 printk_debug("CPU: L1 I Cache: %dK (%d bytes/line), D cache %dK (%d bytes/line)\n",
184 edx>>24, edx&0xFF, ecx>>24, ecx&0xFF);
187 if (n >= 0x80000006) {
189 printk_debug("calling cpuid 0x%08x\n", index);
192 : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
195 printk_debug("CPU: L2 Cache: %dK (%d bytes/line)\n",
196 ecx >> 16, ecx & 0xFF);
205 typedef struct tsc_struct tsc_t;
207 static tsc_t rdtsc(void)
212 : "=a" (res.lo), "=d"(res.hi) /* outputs */
217 static void print_tsc(void) {
221 printk_debug("tsc: 0x%08x%08x\n",
225 printk_debug("tsc: 0x%08x%08x after udelay(1) \n",
230 static void debug_init(device_t dev)
237 switch(dev->path.u.pnp.device) {
240 parent = dev->bus->dev;
241 printk_debug("DEBUG: %s", dev_path(parent));
242 if(parent->chip_ops && parent->chip_ops->name) {
243 printk_debug(": %s\n", parent->chip_ops->name);
251 print_pci_regs_all();
260 print_smbus_regs_all(&dev_root);
263 print_msr_dualcore();
277 static void debug_noop(device_t dummy)
281 static struct device_operations debug_operations = {
282 .read_resources = debug_noop,
283 .set_resources = debug_noop,
284 .enable_resources = debug_noop,
288 static void enable_dev(struct device *dev)
290 dev->ops = &debug_operations;
293 struct chip_operations drivers_generic_debug_ops = {
294 CHIP_NAME("Debug device")
295 .enable_dev = enable_dev,