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>
12 static void print_pci_regs(struct device *dev)
18 byte = pci_read_config8(dev, i);
20 if((i & 0xf)==0) printk(BIOS_DEBUG, "\n%02x:",i);
21 printk(BIOS_DEBUG, " %02x",byte);
23 printk(BIOS_DEBUG, "\n");
26 static void print_mem(void)
29 unsigned int start = 0xfffff000;
30 for(i=start;i<0xffffffff;i++) {
31 if((i & 0xf)==0) printk(BIOS_DEBUG, "\n %08x:",i);
32 printk(BIOS_DEBUG, " %02x",(unsigned char)*((unsigned char *)i));
34 printk(BIOS_DEBUG, " %02x\n",(unsigned char)*((unsigned char *)i));
37 static void print_pci_regs_all(void)
40 unsigned bus, device, function;
42 for(bus=0; bus<256; bus++) {
43 for(device=0; device<=0x1f; device++) {
44 for (function=0; function<=7; function++){
46 devfn = PCI_DEVFN(device, function);
47 dev = dev_find_slot(bus, devfn);
54 printk(BIOS_DEBUG, "\n%02x:%02x:%02x aka %s",
55 bus, device, function, dev_path(dev));
62 static void print_cpuid(void)
66 unsigned eax, ebx, ecx, edx;
68 printk(BIOS_DEBUG, "calling cpuid 0x%08x\n", index);
71 : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
74 printk(BIOS_DEBUG, "cpuid[%08x]: %08x %08x %08x %08x\n",
75 index, eax, ebx, ecx, edx);
78 printk(BIOS_DEBUG, "Reading msr: 0x%08x\n", index);
80 printk(BIOS_DEBUG, "msr[0x%08x]: 0x%08x%08x\n",
81 index, msr.hi, msr.lo);
85 static void print_smbus_regs(struct device *dev)
88 printk(BIOS_DEBUG, "smbus: %s[%d]->", dev_path(dev->bus->dev), dev->bus->link);
89 printk(BIOS_DEBUG, "%s", dev_path(dev));
90 for(j = 0; j < 256; j++) {
93 status = smbus_read_byte(dev, j);
95 // printk(BIOS_DEBUG, "bad device status= %08x\n", status);
99 printk(BIOS_DEBUG, "\n%02x: ", j);
101 byte = status & 0xff;
102 printk(BIOS_DEBUG, "%02x ", byte);
104 printk(BIOS_DEBUG, "\n");
107 static void print_smbus_regs_all(struct device *dev)
109 struct device *child;
111 if (dev->enabled && dev->path.type == DEVICE_PATH_I2C)
113 // Here don't need to call smbus_set_link, because we scan it from top to down
114 if( dev->bus->dev->path.type == DEVICE_PATH_I2C) { // it's under i2c MUX so set mux at first
115 if(ops_smbus_bus(get_pbus_smbus(dev->bus->dev))) {
116 if(dev->bus->dev->ops && dev->bus->dev->ops->set_link)
117 dev->bus->dev->ops->set_link(dev->bus->dev, dev->bus->link);
121 if(ops_smbus_bus(get_pbus_smbus(dev))) print_smbus_regs(dev);
124 for(i=0; i< dev->links; i++) {
125 for (child = dev->link[i].children; child; child = child->sibling) {
126 print_smbus_regs_all(child);
130 static void print_msr_dualcore(void)
134 unsigned eax, ebx, ecx, edx;
136 printk(BIOS_DEBUG, "calling cpuid 0x%08x\n", index);
139 : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
142 printk(BIOS_DEBUG, "cpuid[%08x]: %08x %08x %08x %08x\n",
143 index, eax, ebx, ecx, edx);
145 printk(BIOS_DEBUG, "core number %d\n", ecx & 0xff);
148 printk(BIOS_DEBUG, "Reading msr: 0x%08x\n", index);
150 printk(BIOS_DEBUG, "msr[0x%08x]: 0x%08x%08x bit 54 is %d\n",
151 index, msr.hi, msr.lo, (msr.hi>> (54-32)) & 1);
153 msr.hi |= (1<<(54-32));
157 printk(BIOS_DEBUG, "msr[0x%08x]: 0x%08x%08x\n",
158 index, msr.hi, msr.lo);
163 static void print_cache_size(void)
166 unsigned int n, eax, ebx, ecx, edx;
169 printk(BIOS_DEBUG, "calling cpuid 0x%08x\n", index);
172 : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
177 if (n >= 0x80000005) {
179 printk(BIOS_DEBUG, "calling cpuid 0x%08x\n", index);
182 : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
185 printk(BIOS_DEBUG, "CPU: L1 I Cache: %dK (%d bytes/line), D cache %dK (%d bytes/line)\n",
186 edx>>24, edx&0xFF, ecx>>24, ecx&0xFF);
189 if (n >= 0x80000006) {
191 printk(BIOS_DEBUG, "calling cpuid 0x%08x\n", index);
194 : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
197 printk(BIOS_DEBUG, "CPU: L2 Cache: %dK (%d bytes/line)\n",
198 ecx >> 16, ecx & 0xFF);
207 typedef struct tsc_struct tsc_t;
209 static tsc_t rdtsc(void)
214 : "=a" (res.lo), "=d"(res.hi) /* outputs */
219 static void print_tsc(void) {
223 printk(BIOS_DEBUG, "tsc: 0x%08x%08x\n",
227 printk(BIOS_DEBUG, "tsc: 0x%08x%08x after udelay(1) \n",
232 static void debug_init(device_t dev)
238 switch(dev->path.pnp.device) {
240 parent = dev->bus->dev;
241 printk(BIOS_DEBUG, "DEBUG: %s", dev_path(parent));
242 if(parent->chip_ops && parent->chip_ops->name) {
243 printk(BIOS_DEBUG, ": %s\n", parent->chip_ops->name);
245 printk(BIOS_DEBUG, "\n");
250 print_pci_regs_all();
259 print_smbus_regs_all(&dev_root);
262 print_msr_dualcore();
276 static void debug_noop(device_t dummy)
280 static struct device_operations debug_operations = {
281 .read_resources = debug_noop,
282 .set_resources = debug_noop,
283 .enable_resources = debug_noop,
287 static void enable_dev(struct device *dev)
289 dev->ops = &debug_operations;
292 struct chip_operations drivers_generic_debug_ops = {
293 CHIP_NAME("Debug device")
294 .enable_dev = enable_dev,