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