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>
8 #include <part/hard_reset.h>
12 static void print_pci_regs(struct device *dev)
18 byte = pci_read_config8(dev, i);
20 if((i & 0xf)==0) printk_debug("\n%02x:",i);
21 printk_debug(" %02x",byte);
26 static void print_mem(void)
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));
34 printk_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_debug("\n%02x:%02x:%02x aka %s",
55 bus, device, function, dev_path(dev));
62 static void print_cpuid()
66 unsigned eax, ebx, ecx, edx;
68 printk_debug("calling cpuid 0x%08x\n", index);
71 : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
74 printk_debug("cpuid[%08x]: %08x %08x %08x %08x\n",
75 index, eax, ebx, ecx, edx);
78 printk_debug("Reading msr: 0x%08x\n", index);
80 printk_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_debug("smbus: %s[%d]->", dev_path(dev->bus->dev), dev->bus->link);
89 printk_debug("%s", dev_path(dev));
90 for(j = 0; j < 256; j++) {
93 status = smbus_read_byte(dev, j);
95 // printk_debug("bad device status= %08x\r\n", status);
99 printk_debug("\r\n%02x: ", j);
101 byte = status & 0xff;
102 printk_debug("%02x ", byte);
104 printk_debug("\r\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_debug("calling cpuid 0x%08x\n", index);
139 : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
142 printk_debug("cpuid[%08x]: %08x %08x %08x %08x\n",
143 index, eax, ebx, ecx, edx);
145 printk_debug("core number %d\n", ecx & 0xff);
148 printk_debug("Reading msr: 0x%08x\n", index);
150 printk_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_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_debug("calling cpuid 0x%08x\n", index);
172 : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
177 if (n >= 0x80000005) {
179 printk_debug("calling cpuid 0x%08x\n", index);
182 : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
185 printk_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_debug("calling cpuid 0x%08x\n", index);
194 : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
197 printk_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_debug("tsc: 0x%08x%08x\n",
227 printk_debug("tsc: 0x%08x%08x after udelay(1) \n",
232 static void debug_init(device_t dev)
239 switch(dev->path.pnp.device) {
242 parent = dev->bus->dev;
243 printk_debug("DEBUG: %s", dev_path(parent));
244 if(parent->chip_ops && parent->chip_ops->name) {
245 printk_debug(": %s\n", parent->chip_ops->name);
253 print_pci_regs_all();
262 print_smbus_regs_all(&dev_root);
265 print_msr_dualcore();
279 static void debug_noop(device_t dummy)
283 static struct device_operations debug_operations = {
284 .read_resources = debug_noop,
285 .set_resources = debug_noop,
286 .enable_resources = debug_noop,
290 static void enable_dev(struct device *dev)
292 dev->ops = &debug_operations;
295 struct chip_operations drivers_generic_debug_ops = {
296 CHIP_NAME("Debug device")
297 .enable_dev = enable_dev,