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