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 char 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.hi);
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++) {
92 printk_debug("\r\n%02x: ", j);
94 status = smbus_read_byte(dev, j);
96 printk_debug("bad device status= %08x\r\n", status);
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 debug_init(device_t dev)
133 switch(dev->path.u.pnp.device) {
136 parent = dev->bus->dev;
137 printk_debug("DEBUG: %s", dev_path(parent));
138 if(parent->chip_ops && parent->chip_ops->name) {
139 printk_debug(": %s\n", parent->chip_ops->name);
147 print_pci_regs_all();
156 print_smbus_regs_all(&dev_root);
161 static void debug_noop(device_t dummy)
165 static struct device_operations debug_operations = {
166 .read_resources = debug_noop,
167 .set_resources = debug_noop,
168 .enable_resources = debug_noop,
172 static void enable_dev(struct device *dev)
174 dev->ops = &debug_operations;
177 struct chip_operations drivers_generic_debug_ops = {
178 CHIP_NAME("Debug device")
179 .enable_dev = enable_dev,