Felix Held | 3f3eca9 | 2020-01-23 17:12:32 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | /* This file is part of the coreboot project. */ |
Patrick Rudolph | c162131 | 2019-05-28 11:29:29 +0200 | [diff] [blame] | 3 | |
| 4 | #include <device/device.h> |
| 5 | #include <device/pnp.h> |
| 6 | #include <arch/acpigen.h> |
Patrick Rudolph | c162131 | 2019-05-28 11:29:29 +0200 | [diff] [blame] | 7 | #include <console/console.h> |
| 8 | |
| 9 | static void generic_set_resources(struct device *dev) |
| 10 | { |
| 11 | struct resource *res; |
| 12 | |
Christian Walter | 199f98b | 2019-12-09 13:27:10 +0100 | [diff] [blame] | 13 | if (dev->link_list) |
| 14 | assign_resources(dev->link_list); |
| 15 | |
Patrick Rudolph | c162131 | 2019-05-28 11:29:29 +0200 | [diff] [blame] | 16 | for (res = dev->resource_list; res; res = res->next) { |
| 17 | if (!(res->flags & IORESOURCE_ASSIGNED)) |
| 18 | continue; |
| 19 | |
| 20 | res->flags |= IORESOURCE_STORED; |
| 21 | report_resource_stored(dev, res, ""); |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | static void generic_read_resources(struct device *dev) |
| 26 | { |
| 27 | struct resource *res = new_resource(dev, 0); |
| 28 | res->base = dev->path.pnp.port; |
| 29 | res->size = 2; |
| 30 | res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 31 | } |
| 32 | |
| 33 | #if CONFIG(HAVE_ACPI_TABLES) |
| 34 | static void generic_ssdt(struct device *dev) |
| 35 | { |
| 36 | const char *scope = acpi_device_scope(dev); |
| 37 | const char *name = acpi_device_name(dev); |
| 38 | |
| 39 | if (!scope || !name) { |
Elyes HAOUAS | 4580839 | 2020-03-30 16:43:34 +0200 | [diff] [blame] | 40 | printk(BIOS_ERR, "%s: Missing ACPI path/scope\n", dev_path(dev)); |
Patrick Rudolph | c162131 | 2019-05-28 11:29:29 +0200 | [diff] [blame] | 41 | return; |
| 42 | } |
| 43 | |
| 44 | /* Device */ |
| 45 | acpigen_write_scope(scope); |
| 46 | acpigen_write_device(name); |
| 47 | |
| 48 | printk(BIOS_DEBUG, "%s.%s: %s\n", scope, name, dev_path(dev)); |
| 49 | |
| 50 | acpigen_write_name_string("_HID", "PNP0C02"); |
| 51 | acpigen_write_name_string("_DDN", dev_name(dev)); |
| 52 | |
| 53 | /* OperationRegion("IOID", SYSTEMIO, port, 2) */ |
| 54 | struct opregion opreg = OPREGION("IOID", SYSTEMIO, dev->path.pnp.port, 2); |
| 55 | acpigen_write_opregion(&opreg); |
| 56 | |
| 57 | struct fieldlist l[] = { |
| 58 | FIELDLIST_OFFSET(0), |
| 59 | FIELDLIST_NAMESTR("INDX", 8), |
| 60 | FIELDLIST_NAMESTR("DATA", 8), |
| 61 | }; |
| 62 | |
| 63 | /* Field (IOID, AnyAcc, NoLock, Preserve) |
| 64 | * { |
| 65 | * Offset (0), |
| 66 | * INDX, 8, |
| 67 | * DATA, 8, |
| 68 | * } */ |
| 69 | acpigen_write_field(opreg.name, l, ARRAY_SIZE(l), FIELD_BYTEACC | FIELD_NOLOCK | |
| 70 | FIELD_PRESERVE); |
| 71 | |
| 72 | struct fieldlist i[] = { |
| 73 | FIELDLIST_OFFSET(0x07), |
| 74 | FIELDLIST_NAMESTR("LDN", 8), |
| 75 | FIELDLIST_OFFSET(0x21), |
| 76 | FIELDLIST_NAMESTR("SCF1", 8), |
| 77 | FIELDLIST_NAMESTR("SCF2", 8), |
| 78 | FIELDLIST_NAMESTR("SCF3", 8), |
| 79 | FIELDLIST_NAMESTR("SCF4", 8), |
| 80 | FIELDLIST_NAMESTR("SCF5", 8), |
| 81 | FIELDLIST_NAMESTR("SCF6", 8), |
| 82 | FIELDLIST_NAMESTR("SCF7", 8), |
| 83 | FIELDLIST_OFFSET(0x29), |
| 84 | FIELDLIST_NAMESTR("CKCF", 8), |
| 85 | FIELDLIST_OFFSET(0x2F), |
| 86 | FIELDLIST_NAMESTR("SCFF", 8), |
| 87 | FIELDLIST_OFFSET(0x30), |
| 88 | FIELDLIST_NAMESTR("ACT0", 1), |
| 89 | FIELDLIST_NAMESTR("ACT1", 1), |
| 90 | FIELDLIST_NAMESTR("ACT2", 1), |
| 91 | FIELDLIST_NAMESTR("ACT3", 1), |
| 92 | FIELDLIST_NAMESTR("ACT4", 1), |
| 93 | FIELDLIST_NAMESTR("ACT5", 1), |
| 94 | FIELDLIST_NAMESTR("ACT6", 1), |
| 95 | FIELDLIST_NAMESTR("ACT7", 1), |
| 96 | FIELDLIST_OFFSET(0x60), |
| 97 | FIELDLIST_NAMESTR("IOH0", 8), |
| 98 | FIELDLIST_NAMESTR("IOL0", 8), |
| 99 | FIELDLIST_NAMESTR("IOH1", 8), |
| 100 | FIELDLIST_NAMESTR("IOL1", 8), |
| 101 | FIELDLIST_NAMESTR("IOH2", 8), |
| 102 | FIELDLIST_NAMESTR("IOL2", 8), |
| 103 | FIELDLIST_NAMESTR("IOH3", 8), |
| 104 | FIELDLIST_NAMESTR("IOL3", 8), |
| 105 | FIELDLIST_OFFSET(0x70), |
Michael Niewöhner | 5403a8e | 2019-09-08 18:03:53 +0200 | [diff] [blame] | 106 | /* Interrupt level 0 (IRQ number) */ |
| 107 | FIELDLIST_NAMESTR("ITL0", 4), |
Patrick Rudolph | c162131 | 2019-05-28 11:29:29 +0200 | [diff] [blame] | 108 | FIELDLIST_OFFSET(0x71), |
Michael Niewöhner | 5403a8e | 2019-09-08 18:03:53 +0200 | [diff] [blame] | 109 | /* Interrupt type 0 */ |
| 110 | FIELDLIST_NAMESTR("ITT0", 2), |
Patrick Rudolph | c162131 | 2019-05-28 11:29:29 +0200 | [diff] [blame] | 111 | FIELDLIST_OFFSET(0x72), |
Michael Niewöhner | 5403a8e | 2019-09-08 18:03:53 +0200 | [diff] [blame] | 112 | /* Interrupt level 1 (IRQ number) */ |
| 113 | FIELDLIST_NAMESTR("ITL1", 4), |
Patrick Rudolph | c162131 | 2019-05-28 11:29:29 +0200 | [diff] [blame] | 114 | FIELDLIST_OFFSET(0x73), |
Michael Niewöhner | 5403a8e | 2019-09-08 18:03:53 +0200 | [diff] [blame] | 115 | /* Interrupt type 1 */ |
| 116 | FIELDLIST_NAMESTR("ITT1", 2), |
Patrick Rudolph | c162131 | 2019-05-28 11:29:29 +0200 | [diff] [blame] | 117 | FIELDLIST_OFFSET(0x74), |
| 118 | FIELDLIST_NAMESTR("DMCH", 8), |
| 119 | FIELDLIST_OFFSET(0xE0), |
| 120 | FIELDLIST_NAMESTR("RGE0", 8), |
| 121 | FIELDLIST_NAMESTR("RGE1", 8), |
| 122 | FIELDLIST_NAMESTR("RGE2", 8), |
| 123 | FIELDLIST_NAMESTR("RGE3", 8), |
| 124 | FIELDLIST_NAMESTR("RGE4", 8), |
| 125 | FIELDLIST_NAMESTR("RGE5", 8), |
| 126 | FIELDLIST_NAMESTR("RGE6", 8), |
| 127 | FIELDLIST_NAMESTR("RGE7", 8), |
| 128 | FIELDLIST_NAMESTR("RGE8", 8), |
| 129 | FIELDLIST_NAMESTR("RGE9", 8), |
| 130 | FIELDLIST_NAMESTR("RGEA", 8), |
| 131 | FIELDLIST_OFFSET(0xF0), |
| 132 | FIELDLIST_NAMESTR("OPT0", 8), |
| 133 | FIELDLIST_NAMESTR("OPT1", 8), |
| 134 | FIELDLIST_NAMESTR("OPT2", 8), |
| 135 | FIELDLIST_NAMESTR("OPT3", 8), |
| 136 | FIELDLIST_NAMESTR("OPT4", 8), |
| 137 | FIELDLIST_NAMESTR("OPT5", 8), |
| 138 | FIELDLIST_NAMESTR("OPT6", 8), |
| 139 | FIELDLIST_NAMESTR("OPT7", 8), |
| 140 | FIELDLIST_NAMESTR("OPT8", 8), |
| 141 | FIELDLIST_NAMESTR("OPT9", 8), |
| 142 | }; |
| 143 | |
| 144 | acpigen_write_indexfield("INDX", "DATA", i, ARRAY_SIZE(i), FIELD_BYTEACC | |
| 145 | FIELD_NOLOCK | FIELD_PRESERVE); |
| 146 | |
Patrick Rudolph | 95bff2e | 2019-12-10 14:12:03 +0100 | [diff] [blame] | 147 | const char *mutex = "MTX0"; |
| 148 | |
| 149 | acpigen_write_mutex(mutex, 0); |
| 150 | /* Backup LDN */ |
| 151 | acpigen_write_name_integer("BLDN", 0); |
| 152 | |
| 153 | /* Acquire mutex - Enter config mode */ |
| 154 | acpigen_write_method("AMTX", 0); |
| 155 | { |
| 156 | acpigen_write_acquire(mutex, 0xffff); |
| 157 | |
| 158 | /* Pick one of the children as the generic SIO doesn't have config mode */ |
| 159 | if (dev->link_list && dev->link_list->children) |
| 160 | pnp_ssdt_enter_conf_mode(dev->link_list->children, "^INDX", "^DATA"); |
| 161 | |
| 162 | /* Backup LDN */ |
| 163 | acpigen_write_store(); |
| 164 | acpigen_emit_namestring("^LDN"); |
| 165 | acpigen_emit_namestring("^BLDN"); |
| 166 | } |
| 167 | acpigen_pop_len(); /* Method */ |
| 168 | |
| 169 | /* Release mutex - Exit config mode */ |
| 170 | acpigen_write_method("RMTX", 0); |
| 171 | { |
| 172 | /* Restore LDN */ |
| 173 | acpigen_write_store(); |
| 174 | acpigen_emit_namestring("^BLDN"); |
| 175 | acpigen_emit_namestring("^LDN"); |
| 176 | |
| 177 | /* Pick one of the children as the generic SIO doesn't have config mode */ |
| 178 | if (dev->link_list && dev->link_list->children) |
| 179 | pnp_ssdt_exit_conf_mode(dev->link_list->children, "^INDX", "^DATA"); |
| 180 | |
| 181 | acpigen_write_release(mutex); |
| 182 | } |
| 183 | acpigen_pop_len(); /* Method */ |
| 184 | |
| 185 | /* Select a LDN */ |
| 186 | acpigen_write_method("SLDN", 1); |
| 187 | { |
| 188 | /* Local0 = Arg0 & 0xff */ |
| 189 | acpigen_emit_byte(AND_OP); |
| 190 | acpigen_write_integer(0xff); |
| 191 | acpigen_emit_byte(ARG0_OP); |
| 192 | acpigen_emit_byte(LOCAL0_OP); |
| 193 | |
| 194 | /* LDN = LOCAL0_OP */ |
| 195 | acpigen_write_store(); |
| 196 | acpigen_emit_byte(LOCAL0_OP); |
| 197 | acpigen_emit_namestring("^LDN"); |
| 198 | } |
| 199 | acpigen_pop_len(); /* Method */ |
| 200 | |
| 201 | /* Disable a LDN/VLDN */ |
| 202 | acpigen_write_method("DLDN", 1); |
| 203 | { |
| 204 | /* AMTX() */ |
| 205 | acpigen_emit_namestring("AMTX"); |
| 206 | |
| 207 | /* SLDN (Local0) */ |
| 208 | acpigen_emit_namestring("SLDN"); |
| 209 | acpigen_emit_byte(ARG0_OP); |
| 210 | |
| 211 | /* Local0 = Arg0 >> 8 */ |
| 212 | acpigen_emit_byte(SHIFT_RIGHT_OP); |
| 213 | acpigen_emit_byte(ARG0_OP); |
| 214 | acpigen_write_integer(8); |
| 215 | acpigen_emit_byte(LOCAL0_OP); |
| 216 | |
| 217 | /* Local0 = Local0 & 0x7 */ |
| 218 | acpigen_emit_byte(AND_OP); |
| 219 | acpigen_write_integer(0x7); |
| 220 | acpigen_emit_byte(LOCAL0_OP); |
| 221 | acpigen_emit_byte(LOCAL0_OP); |
| 222 | |
| 223 | for (int j = 0; j < 8; j++) { |
| 224 | char act[6] = "^ACT0"; |
| 225 | act[4] += j; |
| 226 | |
| 227 | /* If (Local0 == j) { */ |
| 228 | acpigen_write_if_lequal_op_int(LOCAL0_OP, j); |
| 229 | |
| 230 | /* ACT[j] = 0 */ |
| 231 | acpigen_write_store(); |
| 232 | acpigen_emit_byte(ZERO_OP); |
| 233 | acpigen_emit_namestring(act); |
| 234 | |
| 235 | acpigen_pop_len(); /* } */ |
| 236 | } |
| 237 | |
| 238 | /* RMTX() */ |
| 239 | acpigen_emit_namestring("RMTX"); |
| 240 | } |
| 241 | acpigen_pop_len(); /* Method */ |
| 242 | |
| 243 | /* Query LDN enable state. Returns 1 if LDN/VLDN is enabled. */ |
| 244 | acpigen_write_method("QLDN", 1); |
| 245 | { |
| 246 | acpigen_emit_namestring("AMTX"); |
| 247 | |
| 248 | /* SLDN (Local0) */ |
| 249 | acpigen_emit_namestring("SLDN"); |
| 250 | acpigen_emit_byte(ARG0_OP); |
| 251 | |
| 252 | /* Local0 = Arg0 >> 8 */ |
| 253 | acpigen_emit_byte(SHIFT_RIGHT_OP); |
| 254 | acpigen_emit_byte(ARG0_OP); |
| 255 | acpigen_write_integer(8); |
| 256 | acpigen_emit_byte(LOCAL0_OP); |
| 257 | |
| 258 | /* Local0 = Local0 & 0x7 */ |
| 259 | acpigen_emit_byte(AND_OP); |
| 260 | acpigen_write_integer(0x7); |
| 261 | acpigen_emit_byte(LOCAL0_OP); |
| 262 | acpigen_emit_byte(LOCAL0_OP); |
| 263 | |
| 264 | for (int j = 0; j < 8; j++) { |
| 265 | char act[6] = "^ACT0"; |
| 266 | act[4] += j; |
| 267 | /* If (Local0 == j) { */ |
| 268 | acpigen_write_if_lequal_op_int(LOCAL0_OP, j); |
| 269 | |
| 270 | /* Local1 = ACT[j] */ |
| 271 | acpigen_write_store(); |
| 272 | acpigen_emit_namestring(act); |
| 273 | acpigen_emit_byte(LOCAL1_OP); |
| 274 | |
| 275 | acpigen_pop_len(); /* } */ |
| 276 | } |
| 277 | |
| 278 | /* RMTX() */ |
| 279 | acpigen_emit_namestring("RMTX"); |
| 280 | |
| 281 | /* Return (Local1) */ |
| 282 | acpigen_emit_byte(RETURN_OP); |
| 283 | acpigen_emit_byte(LOCAL1_OP); |
| 284 | } |
| 285 | acpigen_pop_len(); /* Method */ |
| 286 | |
Patrick Rudolph | c162131 | 2019-05-28 11:29:29 +0200 | [diff] [blame] | 287 | acpigen_pop_len(); /* Device */ |
| 288 | acpigen_pop_len(); /* Scope */ |
| 289 | } |
| 290 | |
| 291 | static const char *generic_acpi_name(const struct device *dev) |
| 292 | { |
| 293 | return "SIO0"; |
| 294 | } |
| 295 | #endif |
| 296 | |
| 297 | static struct device_operations ops = { |
| 298 | .read_resources = generic_read_resources, |
| 299 | .set_resources = generic_set_resources, |
| 300 | .enable_resources = DEVICE_NOOP, |
Christian Walter | 199f98b | 2019-12-09 13:27:10 +0100 | [diff] [blame] | 301 | .scan_bus = scan_static_bus, |
Patrick Rudolph | c162131 | 2019-05-28 11:29:29 +0200 | [diff] [blame] | 302 | #if CONFIG(HAVE_ACPI_TABLES) |
| 303 | .acpi_fill_ssdt_generator = generic_ssdt, |
| 304 | .acpi_name = generic_acpi_name, |
| 305 | #endif |
| 306 | }; |
| 307 | |
| 308 | static void enable_dev(struct device *dev) |
| 309 | { |
| 310 | if (dev->path.type != DEVICE_PATH_PNP) |
| 311 | printk(BIOS_ERR, "%s: Unsupported device type\n", dev_path(dev)); |
| 312 | else if (!dev->path.pnp.port) |
| 313 | printk(BIOS_ERR, "%s: Base address not set\n", dev_path(dev)); |
| 314 | else |
| 315 | dev->ops = &ops; |
| 316 | |
Patrick Rudolph | c162131 | 2019-05-28 11:29:29 +0200 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | struct chip_operations superio_common_ops = { |
| 320 | CHIP_NAME("Generic Super I/O") |
| 321 | .enable_dev = enable_dev, |
| 322 | }; |