9b26bcb90d43f424953105eac81e8523ae1b26b0
[coreboot.git] / src / southbridge / amd / amd8111 / amd8111_reset.c
1 #include <arch/io.h>
2 #include <reset.h>
3 #include <device/pci_ids.h>
4
5 #define PCI_DEV(BUS, DEV, FN) ( \
6         (((BUS) & 0xFFF) << 20) | \
7         (((DEV) & 0x1F) << 15) | \
8         (((FN)  & 0x7) << 12))
9
10 #define PCI_ID(VENDOR_ID, DEVICE_ID) \
11         ((((DEVICE_ID) & 0xFFFF) << 16) | ((VENDOR_ID) & 0xFFFF))
12
13 typedef unsigned device_t;
14
15 static void pci_write_config8(device_t dev, unsigned where, unsigned char value)
16 {
17         unsigned addr;
18         addr = (dev>>4) | where;
19         outl(0x80000000 | (addr & ~3), 0xCF8);
20         outb(value, 0xCFC + (addr & 3));
21 }
22
23 static void pci_write_config32(device_t dev, unsigned where, unsigned value)
24 {
25         unsigned addr;
26         addr = (dev>>4) | where;
27         outl(0x80000000 | (addr & ~3), 0xCF8);
28         outl(value, 0xCFC);
29 }
30
31 static unsigned pci_read_config32(device_t dev, unsigned where)
32 {
33         unsigned addr;
34         addr = (dev>>4) | where;
35         outl(0x80000000 | (addr & ~3), 0xCF8);
36         return inl(0xCFC);
37 }
38
39 #define PCI_DEV_INVALID (0xffffffffU)
40 static device_t pci_locate_device_on_bus(unsigned pci_id, unsigned bus)
41 {
42         device_t dev, last;
43         dev = PCI_DEV(bus, 0, 0);
44         last = PCI_DEV(bus, 31, 7);
45         for(; dev <= last; dev += PCI_DEV(0,0,1)) {
46                 unsigned int id;
47                 id = pci_read_config32(dev, 0);
48                 if (id == pci_id) {
49                         return dev;
50                 }
51         }
52         return PCI_DEV_INVALID;
53 }
54
55 #include "../../../northbridge/amd/amdk8/reset_test.c"
56
57
58 void hard_reset(void)
59 {
60         device_t dev;
61         unsigned bus;
62         unsigned node = 0;
63         unsigned link = get_sblk();
64
65         /* Find the device.
66          * There can only be one 8111 on a hypertransport chain/bus.
67          */
68         bus = node_link_to_bus(node, link);
69         dev = pci_locate_device_on_bus(
70                 PCI_ID(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8111_ISA), 
71                 bus);
72
73         /* Reset */
74         set_bios_reset();
75         pci_write_config8(dev, 0x47, 1);
76 }