Patrick Rudolph | c162131 | 2019-05-28 11:29:29 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | */ |
| 14 | |
| 15 | #include <device/device.h> |
| 16 | #include <device/pnp.h> |
| 17 | #include <arch/acpigen.h> |
Patrick Rudolph | c162131 | 2019-05-28 11:29:29 +0200 | [diff] [blame] | 18 | #include <console/console.h> |
| 19 | |
| 20 | static void generic_set_resources(struct device *dev) |
| 21 | { |
| 22 | struct resource *res; |
| 23 | |
Christian Walter | 199f98b | 2019-12-09 13:27:10 +0100 | [diff] [blame^] | 24 | if (dev->link_list) |
| 25 | assign_resources(dev->link_list); |
| 26 | |
Patrick Rudolph | c162131 | 2019-05-28 11:29:29 +0200 | [diff] [blame] | 27 | for (res = dev->resource_list; res; res = res->next) { |
| 28 | if (!(res->flags & IORESOURCE_ASSIGNED)) |
| 29 | continue; |
| 30 | |
| 31 | res->flags |= IORESOURCE_STORED; |
| 32 | report_resource_stored(dev, res, ""); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | static void generic_read_resources(struct device *dev) |
| 37 | { |
| 38 | struct resource *res = new_resource(dev, 0); |
| 39 | res->base = dev->path.pnp.port; |
| 40 | res->size = 2; |
| 41 | res->flags = IORESOURCE_IO | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 42 | } |
| 43 | |
| 44 | #if CONFIG(HAVE_ACPI_TABLES) |
| 45 | static void generic_ssdt(struct device *dev) |
| 46 | { |
| 47 | const char *scope = acpi_device_scope(dev); |
| 48 | const char *name = acpi_device_name(dev); |
| 49 | |
| 50 | if (!scope || !name) { |
| 51 | printk(BIOS_ERR, "%s: Missing ACPI path/scope\n", |
| 52 | dev_path(dev)); |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | /* Device */ |
| 57 | acpigen_write_scope(scope); |
| 58 | acpigen_write_device(name); |
| 59 | |
| 60 | printk(BIOS_DEBUG, "%s.%s: %s\n", scope, name, dev_path(dev)); |
| 61 | |
| 62 | acpigen_write_name_string("_HID", "PNP0C02"); |
| 63 | acpigen_write_name_string("_DDN", dev_name(dev)); |
| 64 | |
| 65 | /* OperationRegion("IOID", SYSTEMIO, port, 2) */ |
| 66 | struct opregion opreg = OPREGION("IOID", SYSTEMIO, dev->path.pnp.port, 2); |
| 67 | acpigen_write_opregion(&opreg); |
| 68 | |
| 69 | struct fieldlist l[] = { |
| 70 | FIELDLIST_OFFSET(0), |
| 71 | FIELDLIST_NAMESTR("INDX", 8), |
| 72 | FIELDLIST_NAMESTR("DATA", 8), |
| 73 | }; |
| 74 | |
| 75 | /* Field (IOID, AnyAcc, NoLock, Preserve) |
| 76 | * { |
| 77 | * Offset (0), |
| 78 | * INDX, 8, |
| 79 | * DATA, 8, |
| 80 | * } */ |
| 81 | acpigen_write_field(opreg.name, l, ARRAY_SIZE(l), FIELD_BYTEACC | FIELD_NOLOCK | |
| 82 | FIELD_PRESERVE); |
| 83 | |
| 84 | struct fieldlist i[] = { |
| 85 | FIELDLIST_OFFSET(0x07), |
| 86 | FIELDLIST_NAMESTR("LDN", 8), |
| 87 | FIELDLIST_OFFSET(0x21), |
| 88 | FIELDLIST_NAMESTR("SCF1", 8), |
| 89 | FIELDLIST_NAMESTR("SCF2", 8), |
| 90 | FIELDLIST_NAMESTR("SCF3", 8), |
| 91 | FIELDLIST_NAMESTR("SCF4", 8), |
| 92 | FIELDLIST_NAMESTR("SCF5", 8), |
| 93 | FIELDLIST_NAMESTR("SCF6", 8), |
| 94 | FIELDLIST_NAMESTR("SCF7", 8), |
| 95 | FIELDLIST_OFFSET(0x29), |
| 96 | FIELDLIST_NAMESTR("CKCF", 8), |
| 97 | FIELDLIST_OFFSET(0x2F), |
| 98 | FIELDLIST_NAMESTR("SCFF", 8), |
| 99 | FIELDLIST_OFFSET(0x30), |
| 100 | FIELDLIST_NAMESTR("ACT0", 1), |
| 101 | FIELDLIST_NAMESTR("ACT1", 1), |
| 102 | FIELDLIST_NAMESTR("ACT2", 1), |
| 103 | FIELDLIST_NAMESTR("ACT3", 1), |
| 104 | FIELDLIST_NAMESTR("ACT4", 1), |
| 105 | FIELDLIST_NAMESTR("ACT5", 1), |
| 106 | FIELDLIST_NAMESTR("ACT6", 1), |
| 107 | FIELDLIST_NAMESTR("ACT7", 1), |
| 108 | FIELDLIST_OFFSET(0x60), |
| 109 | FIELDLIST_NAMESTR("IOH0", 8), |
| 110 | FIELDLIST_NAMESTR("IOL0", 8), |
| 111 | FIELDLIST_NAMESTR("IOH1", 8), |
| 112 | FIELDLIST_NAMESTR("IOL1", 8), |
| 113 | FIELDLIST_NAMESTR("IOH2", 8), |
| 114 | FIELDLIST_NAMESTR("IOL2", 8), |
| 115 | FIELDLIST_NAMESTR("IOH3", 8), |
| 116 | FIELDLIST_NAMESTR("IOL3", 8), |
| 117 | FIELDLIST_OFFSET(0x70), |
Michael Niewöhner | 5403a8e | 2019-09-08 18:03:53 +0200 | [diff] [blame] | 118 | /* Interrupt level 0 (IRQ number) */ |
| 119 | FIELDLIST_NAMESTR("ITL0", 4), |
Patrick Rudolph | c162131 | 2019-05-28 11:29:29 +0200 | [diff] [blame] | 120 | FIELDLIST_OFFSET(0x71), |
Michael Niewöhner | 5403a8e | 2019-09-08 18:03:53 +0200 | [diff] [blame] | 121 | /* Interrupt type 0 */ |
| 122 | FIELDLIST_NAMESTR("ITT0", 2), |
Patrick Rudolph | c162131 | 2019-05-28 11:29:29 +0200 | [diff] [blame] | 123 | FIELDLIST_OFFSET(0x72), |
Michael Niewöhner | 5403a8e | 2019-09-08 18:03:53 +0200 | [diff] [blame] | 124 | /* Interrupt level 1 (IRQ number) */ |
| 125 | FIELDLIST_NAMESTR("ITL1", 4), |
Patrick Rudolph | c162131 | 2019-05-28 11:29:29 +0200 | [diff] [blame] | 126 | FIELDLIST_OFFSET(0x73), |
Michael Niewöhner | 5403a8e | 2019-09-08 18:03:53 +0200 | [diff] [blame] | 127 | /* Interrupt type 1 */ |
| 128 | FIELDLIST_NAMESTR("ITT1", 2), |
Patrick Rudolph | c162131 | 2019-05-28 11:29:29 +0200 | [diff] [blame] | 129 | FIELDLIST_OFFSET(0x74), |
| 130 | FIELDLIST_NAMESTR("DMCH", 8), |
| 131 | FIELDLIST_OFFSET(0xE0), |
| 132 | FIELDLIST_NAMESTR("RGE0", 8), |
| 133 | FIELDLIST_NAMESTR("RGE1", 8), |
| 134 | FIELDLIST_NAMESTR("RGE2", 8), |
| 135 | FIELDLIST_NAMESTR("RGE3", 8), |
| 136 | FIELDLIST_NAMESTR("RGE4", 8), |
| 137 | FIELDLIST_NAMESTR("RGE5", 8), |
| 138 | FIELDLIST_NAMESTR("RGE6", 8), |
| 139 | FIELDLIST_NAMESTR("RGE7", 8), |
| 140 | FIELDLIST_NAMESTR("RGE8", 8), |
| 141 | FIELDLIST_NAMESTR("RGE9", 8), |
| 142 | FIELDLIST_NAMESTR("RGEA", 8), |
| 143 | FIELDLIST_OFFSET(0xF0), |
| 144 | FIELDLIST_NAMESTR("OPT0", 8), |
| 145 | FIELDLIST_NAMESTR("OPT1", 8), |
| 146 | FIELDLIST_NAMESTR("OPT2", 8), |
| 147 | FIELDLIST_NAMESTR("OPT3", 8), |
| 148 | FIELDLIST_NAMESTR("OPT4", 8), |
| 149 | FIELDLIST_NAMESTR("OPT5", 8), |
| 150 | FIELDLIST_NAMESTR("OPT6", 8), |
| 151 | FIELDLIST_NAMESTR("OPT7", 8), |
| 152 | FIELDLIST_NAMESTR("OPT8", 8), |
| 153 | FIELDLIST_NAMESTR("OPT9", 8), |
| 154 | }; |
| 155 | |
| 156 | acpigen_write_indexfield("INDX", "DATA", i, ARRAY_SIZE(i), FIELD_BYTEACC | |
| 157 | FIELD_NOLOCK | FIELD_PRESERVE); |
| 158 | |
| 159 | acpigen_pop_len(); /* Device */ |
| 160 | acpigen_pop_len(); /* Scope */ |
| 161 | } |
| 162 | |
| 163 | static const char *generic_acpi_name(const struct device *dev) |
| 164 | { |
| 165 | return "SIO0"; |
| 166 | } |
| 167 | #endif |
| 168 | |
| 169 | static struct device_operations ops = { |
| 170 | .read_resources = generic_read_resources, |
| 171 | .set_resources = generic_set_resources, |
| 172 | .enable_resources = DEVICE_NOOP, |
Christian Walter | 199f98b | 2019-12-09 13:27:10 +0100 | [diff] [blame^] | 173 | .scan_bus = scan_static_bus, |
Patrick Rudolph | c162131 | 2019-05-28 11:29:29 +0200 | [diff] [blame] | 174 | #if CONFIG(HAVE_ACPI_TABLES) |
| 175 | .acpi_fill_ssdt_generator = generic_ssdt, |
| 176 | .acpi_name = generic_acpi_name, |
| 177 | #endif |
| 178 | }; |
| 179 | |
| 180 | static void enable_dev(struct device *dev) |
| 181 | { |
| 182 | if (dev->path.type != DEVICE_PATH_PNP) |
| 183 | printk(BIOS_ERR, "%s: Unsupported device type\n", dev_path(dev)); |
| 184 | else if (!dev->path.pnp.port) |
| 185 | printk(BIOS_ERR, "%s: Base address not set\n", dev_path(dev)); |
| 186 | else |
| 187 | dev->ops = &ops; |
| 188 | |
Patrick Rudolph | c162131 | 2019-05-28 11:29:29 +0200 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | struct chip_operations superio_common_ops = { |
| 192 | CHIP_NAME("Generic Super I/O") |
| 193 | .enable_dev = enable_dev, |
| 194 | }; |