Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1 | /* |
Stefan Reinauer | 7e61e45 | 2008-01-18 10:35:56 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 3 | * |
Timothy Pearson | 82982a1 | 2015-01-23 20:26:31 -0600 | [diff] [blame] | 4 | * Copyright (C) 2015 Timothy Pearson <tpearson@raptorengineeringinc.com>, Raptor Engineering |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 5 | * Copyright (C) 2007 Advanced Micro Devices, Inc. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
Damien Zammit | 75a3d1f | 2016-11-28 00:29:10 +1100 | [diff] [blame] | 17 | #include <inttypes.h> |
| 18 | #include <console/console.h> |
| 19 | #include <northbridge/amd/amdfam10/raminit.h> |
| 20 | #include <northbridge/amd/amdfam10/amdfam10.h> |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 21 | |
| 22 | #define RES_DEBUG 0 |
| 23 | |
Damien Zammit | 75a3d1f | 2016-11-28 00:29:10 +1100 | [diff] [blame] | 24 | void setup_resource_map(const u32 *register_values, u32 max) |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 25 | { |
| 26 | u32 i; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 27 | |
Elyes HAOUAS | 5a7e72f | 2016-08-23 21:36:02 +0200 | [diff] [blame] | 28 | for (i = 0; i < max; i += 3) { |
Antonello Dettori | f65ccb2 | 2016-09-03 10:45:33 +0200 | [diff] [blame] | 29 | pci_devfn_t dev; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 30 | u32 where; |
| 31 | u32 reg; |
| 32 | |
| 33 | dev = register_values[i] & ~0xff; |
| 34 | where = register_values[i] & 0xff; |
| 35 | reg = pci_read_config32(dev, where); |
| 36 | reg &= register_values[i+1]; |
| 37 | reg |= register_values[i+2]; |
| 38 | pci_write_config32(dev, where, reg); |
| 39 | } |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | |
Stefan Reinauer | 817d754 | 2010-07-08 00:37:23 +0000 | [diff] [blame] | 43 | void setup_resource_map_offset(const u32 *register_values, u32 max, u32 offset_pci_dev, u32 offset_io_base) |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 44 | { |
| 45 | u32 i; |
Elyes HAOUAS | e0ee4c8 | 2016-10-04 20:58:03 +0200 | [diff] [blame] | 46 | |
Elyes HAOUAS | 5a7e72f | 2016-08-23 21:36:02 +0200 | [diff] [blame] | 47 | for (i = 0; i < max; i += 3) { |
Antonello Dettori | f65ccb2 | 2016-09-03 10:45:33 +0200 | [diff] [blame] | 48 | pci_devfn_t dev; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 49 | u32 where; |
| 50 | unsigned long reg; |
| 51 | dev = (register_values[i] & ~0xfff) + offset_pci_dev; |
| 52 | where = register_values[i] & 0xfff; |
| 53 | reg = pci_read_config32(dev, where); |
| 54 | reg &= register_values[i+1]; |
| 55 | reg |= register_values[i+2] + offset_io_base; |
| 56 | pci_write_config32(dev, where, reg); |
| 57 | } |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Stefan Reinauer | 817d754 | 2010-07-08 00:37:23 +0000 | [diff] [blame] | 60 | void setup_resource_map_x_offset(const u32 *register_values, u32 max, u32 offset_pci_dev, u32 offset_io_base) |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 61 | { |
| 62 | u32 i; |
| 63 | |
Timothy Pearson | 82982a1 | 2015-01-23 20:26:31 -0600 | [diff] [blame] | 64 | if (IS_ENABLED(RES_DEBUG)) |
| 65 | printk(BIOS_DEBUG, "setting up resource map ex offset....\n"); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 66 | |
Elyes HAOUAS | 5a7e72f | 2016-08-23 21:36:02 +0200 | [diff] [blame] | 67 | for (i = 0; i < max; i += 4) { |
Timothy Pearson | 82982a1 | 2015-01-23 20:26:31 -0600 | [diff] [blame] | 68 | if (IS_ENABLED(RES_DEBUG)) |
| 69 | printk(BIOS_DEBUG, "%04x: %02x %08x <- & %08x | %08x\n", |
| 70 | i/4, register_values[i], |
Elyes HAOUAS | 04f8fd9 | 2016-09-19 10:24:34 -0600 | [diff] [blame] | 71 | register_values[i+1] + ((register_values[i]==RES_PCI_IO) ? offset_pci_dev : 0), |
Timothy Pearson | 82982a1 | 2015-01-23 20:26:31 -0600 | [diff] [blame] | 72 | register_values[i+2], |
Elyes HAOUAS | 04f8fd9 | 2016-09-19 10:24:34 -0600 | [diff] [blame] | 73 | register_values[i+3] + (((register_values[i] & RES_PORT_IO_32) == RES_PORT_IO_32) ? offset_io_base : 0) |
Timothy Pearson | 82982a1 | 2015-01-23 20:26:31 -0600 | [diff] [blame] | 74 | ); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 75 | switch (register_values[i]) { |
| 76 | case RES_PCI_IO: //PCI |
| 77 | { |
Antonello Dettori | f65ccb2 | 2016-09-03 10:45:33 +0200 | [diff] [blame] | 78 | pci_devfn_t dev; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 79 | u32 where; |
| 80 | u32 reg; |
| 81 | dev = (register_values[i+1] & ~0xfff) + offset_pci_dev; |
| 82 | where = register_values[i+1] & 0xfff; |
| 83 | reg = pci_read_config32(dev, where); |
Timothy Pearson | 82982a1 | 2015-01-23 20:26:31 -0600 | [diff] [blame] | 84 | if (IS_ENABLED(RES_DEBUG)) |
| 85 | printk(BIOS_SPEW, "WAS: %08x\n", reg); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 86 | reg &= register_values[i+2]; |
| 87 | reg |= register_values[i+3]; |
| 88 | pci_write_config32(dev, where, reg); |
Timothy Pearson | 82982a1 | 2015-01-23 20:26:31 -0600 | [diff] [blame] | 89 | if (IS_ENABLED(RES_DEBUG)) |
| 90 | printk(BIOS_SPEW, "NOW: %08x\n", reg); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 91 | } |
| 92 | break; |
| 93 | case RES_PORT_IO_8: // io 8 |
| 94 | { |
| 95 | u32 where; |
| 96 | u32 reg; |
| 97 | where = register_values[i+1] + offset_io_base; |
| 98 | reg = inb(where); |
Timothy Pearson | 82982a1 | 2015-01-23 20:26:31 -0600 | [diff] [blame] | 99 | if (IS_ENABLED(RES_DEBUG)) |
| 100 | printk(BIOS_SPEW, "WAS: %08x\n", reg); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 101 | reg &= register_values[i+2]; |
| 102 | reg |= register_values[i+3]; |
| 103 | outb(reg, where); |
Timothy Pearson | 82982a1 | 2015-01-23 20:26:31 -0600 | [diff] [blame] | 104 | if (IS_ENABLED(RES_DEBUG)) |
| 105 | printk(BIOS_SPEW, "NOW: %08x\n", reg); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 106 | } |
| 107 | break; |
| 108 | case RES_PORT_IO_32: //io32 |
| 109 | { |
| 110 | u32 where; |
| 111 | u32 reg; |
| 112 | where = register_values[i+1] + offset_io_base; |
| 113 | reg = inl(where); |
Timothy Pearson | 82982a1 | 2015-01-23 20:26:31 -0600 | [diff] [blame] | 114 | if (IS_ENABLED(RES_DEBUG)) |
| 115 | printk(BIOS_SPEW, "WAS: %08x\n", reg); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 116 | reg &= register_values[i+2]; |
| 117 | reg |= register_values[i+3]; |
| 118 | outl(reg, where); |
Timothy Pearson | 82982a1 | 2015-01-23 20:26:31 -0600 | [diff] [blame] | 119 | if (IS_ENABLED(RES_DEBUG)) |
| 120 | printk(BIOS_SPEW, "NOW: %08x\n", reg); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 121 | } |
| 122 | break; |
Elyes HAOUAS | e0ee4c8 | 2016-10-04 20:58:03 +0200 | [diff] [blame] | 123 | } |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 124 | } |
| 125 | |
Timothy Pearson | 82982a1 | 2015-01-23 20:26:31 -0600 | [diff] [blame] | 126 | if (IS_ENABLED(RES_DEBUG)) |
| 127 | printk(BIOS_DEBUG, "done.\n"); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 128 | } |
Stefan Reinauer | 817d754 | 2010-07-08 00:37:23 +0000 | [diff] [blame] | 129 | |
| 130 | void setup_resource_map_x(const u32 *register_values, u32 max) |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 131 | { |
| 132 | u32 i; |
| 133 | |
Timothy Pearson | 82982a1 | 2015-01-23 20:26:31 -0600 | [diff] [blame] | 134 | if (IS_ENABLED(RES_DEBUG)) |
| 135 | printk(BIOS_DEBUG, "setting up resource map ex offset....\n"); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 136 | |
Elyes HAOUAS | 5a7e72f | 2016-08-23 21:36:02 +0200 | [diff] [blame] | 137 | for (i = 0; i < max; i += 4) { |
Timothy Pearson | 82982a1 | 2015-01-23 20:26:31 -0600 | [diff] [blame] | 138 | if (IS_ENABLED(RES_DEBUG)) |
| 139 | printk(BIOS_DEBUG, "%04x: %02x %08x <- & %08x | %08x\n", |
| 140 | i/4, register_values[i],register_values[i+1], register_values[i+2], register_values[i+3]); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 141 | switch (register_values[i]) { |
| 142 | case RES_PCI_IO: //PCI |
| 143 | { |
Antonello Dettori | f65ccb2 | 2016-09-03 10:45:33 +0200 | [diff] [blame] | 144 | pci_devfn_t dev; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 145 | u32 where; |
| 146 | u32 reg; |
| 147 | dev = register_values[i+1] & ~0xff; |
| 148 | where = register_values[i+1] & 0xff; |
| 149 | reg = pci_read_config32(dev, where); |
| 150 | reg &= register_values[i+2]; |
| 151 | reg |= register_values[i+3]; |
| 152 | pci_write_config32(dev, where, reg); |
| 153 | } |
| 154 | break; |
| 155 | case RES_PORT_IO_8: // io 8 |
| 156 | { |
| 157 | u32 where; |
| 158 | u32 reg; |
| 159 | where = register_values[i+1]; |
| 160 | reg = inb(where); |
| 161 | reg &= register_values[i+2]; |
| 162 | reg |= register_values[i+3]; |
| 163 | outb(reg, where); |
| 164 | } |
| 165 | break; |
| 166 | case RES_PORT_IO_32: //io32 |
| 167 | { |
| 168 | u32 where; |
| 169 | u32 reg; |
| 170 | where = register_values[i+1]; |
| 171 | reg = inl(where); |
| 172 | reg &= register_values[i+2]; |
| 173 | reg |= register_values[i+3]; |
| 174 | outl(reg, where); |
| 175 | } |
| 176 | break; |
Elyes HAOUAS | e0ee4c8 | 2016-10-04 20:58:03 +0200 | [diff] [blame] | 177 | } |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 178 | } |
| 179 | |
Timothy Pearson | 82982a1 | 2015-01-23 20:26:31 -0600 | [diff] [blame] | 180 | if (IS_ENABLED(RES_DEBUG)) |
| 181 | printk(BIOS_DEBUG, "done.\n"); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 182 | } |