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 | |
| 17 | |
| 18 | #define RES_DEBUG 0 |
| 19 | |
| 20 | static void setup_resource_map(const u32 *register_values, u32 max) |
| 21 | { |
| 22 | u32 i; |
Stefan Reinauer | 65b72ab | 2015-01-05 12:59:54 -0800 | [diff] [blame] | 23 | // printk(BIOS_DEBUG, "setting up resource map...."); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 24 | |
| 25 | for(i = 0; i < max; i += 3) { |
| 26 | device_t dev; |
| 27 | u32 where; |
| 28 | u32 reg; |
| 29 | |
| 30 | dev = register_values[i] & ~0xff; |
| 31 | where = register_values[i] & 0xff; |
| 32 | reg = pci_read_config32(dev, where); |
| 33 | reg &= register_values[i+1]; |
| 34 | reg |= register_values[i+2]; |
| 35 | pci_write_config32(dev, where, reg); |
| 36 | } |
Stefan Reinauer | 65b72ab | 2015-01-05 12:59:54 -0800 | [diff] [blame] | 37 | // printk(BIOS_DEBUG, "done.\n"); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | |
Stefan Reinauer | 817d754 | 2010-07-08 00:37:23 +0000 | [diff] [blame] | 41 | 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] | 42 | { |
| 43 | u32 i; |
Stefan Reinauer | 65b72ab | 2015-01-05 12:59:54 -0800 | [diff] [blame] | 44 | // printk(BIOS_DEBUG, "setting up resource map offset...."); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 45 | for(i = 0; i < max; i += 3) { |
| 46 | device_t dev; |
| 47 | u32 where; |
| 48 | unsigned long reg; |
| 49 | dev = (register_values[i] & ~0xfff) + offset_pci_dev; |
| 50 | where = register_values[i] & 0xfff; |
| 51 | reg = pci_read_config32(dev, where); |
| 52 | reg &= register_values[i+1]; |
| 53 | reg |= register_values[i+2] + offset_io_base; |
| 54 | pci_write_config32(dev, where, reg); |
| 55 | } |
Stefan Reinauer | 65b72ab | 2015-01-05 12:59:54 -0800 | [diff] [blame] | 56 | // printk(BIOS_DEBUG, "done.\n"); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | #define RES_PCI_IO 0x10 |
| 60 | #define RES_PORT_IO_8 0x22 |
| 61 | #define RES_PORT_IO_32 0x20 |
| 62 | #define RES_MEM_IO 0x40 |
| 63 | |
Stefan Reinauer | 817d754 | 2010-07-08 00:37:23 +0000 | [diff] [blame] | 64 | 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] | 65 | { |
| 66 | u32 i; |
| 67 | |
Timothy Pearson | 82982a1 | 2015-01-23 20:26:31 -0600 | [diff] [blame] | 68 | if (IS_ENABLED(RES_DEBUG)) |
| 69 | printk(BIOS_DEBUG, "setting up resource map ex offset....\n"); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 70 | |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 71 | for(i = 0; i < max; i += 4) { |
Timothy Pearson | 82982a1 | 2015-01-23 20:26:31 -0600 | [diff] [blame] | 72 | if (IS_ENABLED(RES_DEBUG)) |
| 73 | printk(BIOS_DEBUG, "%04x: %02x %08x <- & %08x | %08x\n", |
| 74 | i/4, register_values[i], |
| 75 | register_values[i+1] + ( (register_values[i]==RES_PCI_IO) ? offset_pci_dev : 0), |
| 76 | register_values[i+2], |
| 77 | register_values[i+3] + ( ( (register_values[i] & RES_PORT_IO_32) == RES_PORT_IO_32) ? offset_io_base : 0) |
| 78 | ); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 79 | switch (register_values[i]) { |
| 80 | case RES_PCI_IO: //PCI |
| 81 | { |
| 82 | device_t dev; |
| 83 | u32 where; |
| 84 | u32 reg; |
| 85 | dev = (register_values[i+1] & ~0xfff) + offset_pci_dev; |
| 86 | where = register_values[i+1] & 0xfff; |
| 87 | reg = pci_read_config32(dev, where); |
Timothy Pearson | 82982a1 | 2015-01-23 20:26:31 -0600 | [diff] [blame] | 88 | if (IS_ENABLED(RES_DEBUG)) |
| 89 | printk(BIOS_SPEW, "WAS: %08x\n", reg); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 90 | reg &= register_values[i+2]; |
| 91 | reg |= register_values[i+3]; |
| 92 | pci_write_config32(dev, where, reg); |
Timothy Pearson | 82982a1 | 2015-01-23 20:26:31 -0600 | [diff] [blame] | 93 | if (IS_ENABLED(RES_DEBUG)) |
| 94 | printk(BIOS_SPEW, "NOW: %08x\n", reg); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 95 | } |
| 96 | break; |
| 97 | case RES_PORT_IO_8: // io 8 |
| 98 | { |
| 99 | u32 where; |
| 100 | u32 reg; |
| 101 | where = register_values[i+1] + offset_io_base; |
| 102 | reg = inb(where); |
Timothy Pearson | 82982a1 | 2015-01-23 20:26:31 -0600 | [diff] [blame] | 103 | if (IS_ENABLED(RES_DEBUG)) |
| 104 | printk(BIOS_SPEW, "WAS: %08x\n", reg); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 105 | reg &= register_values[i+2]; |
| 106 | reg |= register_values[i+3]; |
| 107 | outb(reg, where); |
Timothy Pearson | 82982a1 | 2015-01-23 20:26:31 -0600 | [diff] [blame] | 108 | if (IS_ENABLED(RES_DEBUG)) |
| 109 | printk(BIOS_SPEW, "NOW: %08x\n", reg); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 110 | } |
| 111 | break; |
| 112 | case RES_PORT_IO_32: //io32 |
| 113 | { |
| 114 | u32 where; |
| 115 | u32 reg; |
| 116 | where = register_values[i+1] + offset_io_base; |
| 117 | reg = inl(where); |
Timothy Pearson | 82982a1 | 2015-01-23 20:26:31 -0600 | [diff] [blame] | 118 | if (IS_ENABLED(RES_DEBUG)) |
| 119 | printk(BIOS_SPEW, "WAS: %08x\n", reg); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 120 | reg &= register_values[i+2]; |
| 121 | reg |= register_values[i+3]; |
| 122 | outl(reg, where); |
Timothy Pearson | 82982a1 | 2015-01-23 20:26:31 -0600 | [diff] [blame] | 123 | if (IS_ENABLED(RES_DEBUG)) |
| 124 | printk(BIOS_SPEW, "NOW: %08x\n", reg); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 125 | } |
| 126 | break; |
| 127 | } // switch |
| 128 | |
| 129 | |
| 130 | } |
| 131 | |
Timothy Pearson | 82982a1 | 2015-01-23 20:26:31 -0600 | [diff] [blame] | 132 | if (IS_ENABLED(RES_DEBUG)) |
| 133 | printk(BIOS_DEBUG, "done.\n"); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 134 | } |
Stefan Reinauer | 817d754 | 2010-07-08 00:37:23 +0000 | [diff] [blame] | 135 | |
| 136 | void setup_resource_map_x(const u32 *register_values, u32 max) |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 137 | { |
| 138 | u32 i; |
| 139 | |
Timothy Pearson | 82982a1 | 2015-01-23 20:26:31 -0600 | [diff] [blame] | 140 | if (IS_ENABLED(RES_DEBUG)) |
| 141 | printk(BIOS_DEBUG, "setting up resource map ex offset....\n"); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 142 | |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 143 | for(i = 0; i < max; i += 4) { |
Timothy Pearson | 82982a1 | 2015-01-23 20:26:31 -0600 | [diff] [blame] | 144 | if (IS_ENABLED(RES_DEBUG)) |
| 145 | printk(BIOS_DEBUG, "%04x: %02x %08x <- & %08x | %08x\n", |
| 146 | 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] | 147 | switch (register_values[i]) { |
| 148 | case RES_PCI_IO: //PCI |
| 149 | { |
| 150 | device_t dev; |
| 151 | u32 where; |
| 152 | u32 reg; |
| 153 | dev = register_values[i+1] & ~0xff; |
| 154 | where = register_values[i+1] & 0xff; |
| 155 | reg = pci_read_config32(dev, where); |
| 156 | reg &= register_values[i+2]; |
| 157 | reg |= register_values[i+3]; |
| 158 | pci_write_config32(dev, where, reg); |
| 159 | } |
| 160 | break; |
| 161 | case RES_PORT_IO_8: // io 8 |
| 162 | { |
| 163 | u32 where; |
| 164 | u32 reg; |
| 165 | where = register_values[i+1]; |
| 166 | reg = inb(where); |
| 167 | reg &= register_values[i+2]; |
| 168 | reg |= register_values[i+3]; |
| 169 | outb(reg, where); |
| 170 | } |
| 171 | break; |
| 172 | case RES_PORT_IO_32: //io32 |
| 173 | { |
| 174 | u32 where; |
| 175 | u32 reg; |
| 176 | where = register_values[i+1]; |
| 177 | reg = inl(where); |
| 178 | reg &= register_values[i+2]; |
| 179 | reg |= register_values[i+3]; |
| 180 | outl(reg, where); |
| 181 | } |
| 182 | break; |
| 183 | } // switch |
| 184 | |
| 185 | |
| 186 | } |
| 187 | |
Timothy Pearson | 82982a1 | 2015-01-23 20:26:31 -0600 | [diff] [blame] | 188 | if (IS_ENABLED(RES_DEBUG)) |
| 189 | printk(BIOS_DEBUG, "done.\n"); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 190 | } |
| 191 | |
Stefan Reinauer | c51dc44 | 2010-04-07 01:44:04 +0000 | [diff] [blame] | 192 | #if 0 |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 193 | static void setup_iob_resource_map(const u32 *register_values, u32 max) |
| 194 | { |
| 195 | u32 i; |
| 196 | |
| 197 | for(i = 0; i < max; i += 3) { |
| 198 | u32 where; |
| 199 | u32 reg; |
| 200 | |
| 201 | where = register_values[i]; |
| 202 | reg = inb(where); |
| 203 | reg &= register_values[i+1]; |
| 204 | reg |= register_values[i+2]; |
| 205 | outb(reg, where); |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | static void setup_io_resource_map(const u32 *register_values, u32 max) |
| 210 | { |
| 211 | u32 i; |
| 212 | |
| 213 | for(i = 0; i < max; i += 3) { |
| 214 | u32 where; |
| 215 | u32 reg; |
| 216 | |
| 217 | where = register_values[i]; |
| 218 | reg = inl(where); |
| 219 | reg &= register_values[i+1]; |
| 220 | reg |= register_values[i+2]; |
| 221 | |
| 222 | outl(reg, where); |
| 223 | } |
| 224 | } |
Stefan Reinauer | c51dc44 | 2010-04-07 01:44:04 +0000 | [diff] [blame] | 225 | #endif |