Angel Pons | c74dae9 | 2020-04-02 23:48:16 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 2 | |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 3 | #include <arch/io.h> |
Elyes Haouas | 04c3b5a | 2022-10-07 10:08:05 +0200 | [diff] [blame] | 4 | #include <console/console.h> |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 5 | #include <device/device.h> |
| 6 | #include <device/pnp.h> |
Elyes Haouas | 04c3b5a | 2022-10-07 10:08:05 +0200 | [diff] [blame] | 7 | #include <stdint.h> |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 8 | |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 9 | /* PNP config mode wrappers */ |
| 10 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 11 | void pnp_enter_conf_mode(struct device *dev) |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 12 | { |
| 13 | if (dev->ops->ops_pnp_mode) |
| 14 | dev->ops->ops_pnp_mode->enter_conf_mode(dev); |
| 15 | } |
| 16 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 17 | void pnp_exit_conf_mode(struct device *dev) |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 18 | { |
| 19 | if (dev->ops->ops_pnp_mode) |
| 20 | dev->ops->ops_pnp_mode->exit_conf_mode(dev); |
| 21 | } |
| 22 | |
Patrick Rudolph | 7db16dd | 2019-12-10 13:15:42 +0100 | [diff] [blame] | 23 | #if CONFIG(HAVE_ACPI_TABLES) |
| 24 | void pnp_ssdt_enter_conf_mode(struct device *dev, const char *idx, const char *data) |
| 25 | { |
| 26 | if (dev->ops->ops_pnp_mode && dev->ops->ops_pnp_mode->ssdt_enter_conf_mode) |
| 27 | dev->ops->ops_pnp_mode->ssdt_enter_conf_mode(dev, idx, data); |
| 28 | } |
| 29 | void pnp_ssdt_exit_conf_mode(struct device *dev, const char *idx, const char *data) |
| 30 | { |
| 31 | if (dev->ops->ops_pnp_mode && dev->ops->ops_pnp_mode->ssdt_exit_conf_mode) |
| 32 | dev->ops->ops_pnp_mode->ssdt_exit_conf_mode(dev, idx, data); |
| 33 | } |
| 34 | #endif |
| 35 | |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 36 | /* PNP fundamental operations */ |
| 37 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 38 | void pnp_write_config(struct device *dev, u8 reg, u8 value) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 39 | { |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 40 | outb(reg, dev->path.pnp.port); |
| 41 | outb(value, dev->path.pnp.port + 1); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 44 | u8 pnp_read_config(struct device *dev, u8 reg) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 45 | { |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 46 | outb(reg, dev->path.pnp.port); |
| 47 | return inb(dev->path.pnp.port + 1); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Angel Pons | bb8d00d | 2021-06-06 19:20:48 +0200 | [diff] [blame] | 50 | void pnp_unset_and_set_config(struct device *dev, u8 reg, u8 unset, u8 set) |
| 51 | { |
| 52 | outb(reg, dev->path.pnp.port); |
| 53 | u8 value = inb(dev->path.pnp.port + 1); |
| 54 | value &= ~unset; |
| 55 | value |= set; |
| 56 | outb(value, dev->path.pnp.port + 1); |
| 57 | } |
| 58 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 59 | void pnp_set_logical_device(struct device *dev) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 60 | { |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 61 | pnp_write_config(dev, 0x07, dev->path.pnp.device & 0xff); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 62 | } |
| 63 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 64 | void pnp_set_enable(struct device *dev, int enable) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 65 | { |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 66 | u8 tmp, bitpos; |
Rudolf Marek | 623df67 | 2008-02-18 20:32:46 +0000 | [diff] [blame] | 67 | |
Elyes HAOUAS | 79a3de1 | 2020-08-26 19:52:40 +0200 | [diff] [blame] | 68 | tmp = pnp_read_config(dev, PNP_IDX_EN); |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 69 | |
| 70 | /* Handle virtual devices, which share the same LDN register. */ |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 71 | bitpos = (dev->path.pnp.device >> 8) & 0x7; |
Rudolf Marek | 623df67 | 2008-02-18 20:32:46 +0000 | [diff] [blame] | 72 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 73 | if (enable) |
Rudolf Marek | 623df67 | 2008-02-18 20:32:46 +0000 | [diff] [blame] | 74 | tmp |= (1 << bitpos); |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 75 | else |
Rudolf Marek | 623df67 | 2008-02-18 20:32:46 +0000 | [diff] [blame] | 76 | tmp &= ~(1 << bitpos); |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 77 | |
Elyes HAOUAS | 79a3de1 | 2020-08-26 19:52:40 +0200 | [diff] [blame] | 78 | pnp_write_config(dev, PNP_IDX_EN, tmp); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 79 | } |
| 80 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 81 | int pnp_read_enable(struct device *dev) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 82 | { |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 83 | u8 tmp, bitpos; |
| 84 | |
Elyes HAOUAS | 79a3de1 | 2020-08-26 19:52:40 +0200 | [diff] [blame] | 85 | tmp = pnp_read_config(dev, PNP_IDX_EN); |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 86 | |
| 87 | /* Handle virtual devices, which share the same LDN register. */ |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 88 | bitpos = (dev->path.pnp.device >> 8) & 0x7; |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 89 | |
Rudolf Marek | b05d4bb | 2008-02-19 20:30:25 +0000 | [diff] [blame] | 90 | return !!(tmp & (1 << bitpos)); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 91 | } |
| 92 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 93 | void pnp_set_iobase(struct device *dev, u8 index, u16 iobase) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 94 | { |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 95 | /* Index == 0x60 or 0x62. */ |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 96 | pnp_write_config(dev, index + 0, (iobase >> 8) & 0xff); |
| 97 | pnp_write_config(dev, index + 1, iobase & 0xff); |
| 98 | } |
| 99 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 100 | void pnp_set_irq(struct device *dev, u8 index, u8 irq) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 101 | { |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 102 | /* Index == 0x70 or 0x72. */ |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 103 | pnp_write_config(dev, index, irq); |
| 104 | } |
| 105 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 106 | void pnp_set_drq(struct device *dev, u8 index, u8 drq) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 107 | { |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 108 | /* Index == 0x74. */ |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 109 | pnp_write_config(dev, index, drq & 0xff); |
| 110 | } |
| 111 | |
| 112 | /* PNP device operations */ |
| 113 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 114 | void pnp_read_resources(struct device *dev) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 115 | { |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 118 | static void pnp_set_resource(struct device *dev, struct resource *resource) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 119 | { |
| 120 | if (!(resource->flags & IORESOURCE_ASSIGNED)) { |
Felix Held | 9362b19 | 2024-02-28 12:20:41 +0100 | [diff] [blame] | 121 | printk(BIOS_NOTICE, "%s %02lx %s size: 0x%010llx not assigned in devicetree\n", |
| 122 | dev_path(dev), resource->index, resource_type(resource), |
| 123 | resource->size); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 124 | return; |
| 125 | } |
Li-Ta Lo | 75337f7 | 2004-05-07 21:56:48 +0000 | [diff] [blame] | 126 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 127 | /* Now store the resource. */ |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 128 | if (resource->flags & IORESOURCE_IO) { |
| 129 | pnp_set_iobase(dev, resource->index, resource->base); |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 130 | } else if (resource->flags & IORESOURCE_DRQ) { |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 131 | pnp_set_drq(dev, resource->index, resource->base); |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 132 | } else if (resource->flags & IORESOURCE_IRQ) { |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 133 | pnp_set_irq(dev, resource->index, resource->base); |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 134 | } else { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 135 | printk(BIOS_ERR, "%s %02lx unknown resource type\n", |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 136 | dev_path(dev), resource->index); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 137 | return; |
| 138 | } |
Li-Ta Lo | 9f0d0f9 | 2004-05-10 16:05:16 +0000 | [diff] [blame] | 139 | resource->flags |= IORESOURCE_STORED; |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 140 | |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 141 | report_resource_stored(dev, resource, ""); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 142 | } |
| 143 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 144 | void pnp_set_resources(struct device *dev) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 145 | { |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 146 | struct resource *res; |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 147 | |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 148 | pnp_enter_conf_mode(dev); |
| 149 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 150 | /* Select the logical device (LDN). */ |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 151 | pnp_set_logical_device(dev); |
| 152 | |
| 153 | /* Paranoia says I should disable the device here... */ |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 154 | for (res = dev->resource_list; res; res = res->next) |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 155 | pnp_set_resource(dev, res); |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 156 | |
| 157 | pnp_exit_conf_mode(dev); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 158 | } |
| 159 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 160 | void pnp_enable_resources(struct device *dev) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 161 | { |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 162 | pnp_enter_conf_mode(dev); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 163 | pnp_set_logical_device(dev); |
| 164 | pnp_set_enable(dev, 1); |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 165 | pnp_exit_conf_mode(dev); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 166 | } |
| 167 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 168 | void pnp_enable(struct device *dev) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 169 | { |
Li-Ta Lo | 75337f7 | 2004-05-07 21:56:48 +0000 | [diff] [blame] | 170 | if (!dev->enabled) { |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 171 | pnp_enter_conf_mode(dev); |
Li-Ta Lo | c6bcedb | 2004-04-21 16:57:05 +0000 | [diff] [blame] | 172 | pnp_set_logical_device(dev); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 173 | pnp_set_enable(dev, 0); |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 174 | pnp_exit_conf_mode(dev); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 175 | } |
| 176 | } |
| 177 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 178 | void pnp_alt_enable(struct device *dev) |
Nico Huber | f898f7b | 2013-06-10 22:57:12 +0200 | [diff] [blame] | 179 | { |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 180 | pnp_enter_conf_mode(dev); |
Nico Huber | f898f7b | 2013-06-10 22:57:12 +0200 | [diff] [blame] | 181 | pnp_set_logical_device(dev); |
| 182 | pnp_set_enable(dev, !!dev->enabled); |
Nico Huber | dd4715b | 2013-06-10 22:08:35 +0200 | [diff] [blame] | 183 | pnp_exit_conf_mode(dev); |
Nico Huber | f898f7b | 2013-06-10 22:57:12 +0200 | [diff] [blame] | 184 | } |
| 185 | |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 186 | struct device_operations pnp_ops = { |
| 187 | .read_resources = pnp_read_resources, |
| 188 | .set_resources = pnp_set_resources, |
| 189 | .enable_resources = pnp_enable_resources, |
| 190 | .enable = pnp_enable, |
| 191 | }; |
| 192 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 193 | /* PNP chip operations */ |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 194 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 195 | static void pnp_get_ioresource(struct device *dev, u8 index, u16 mask) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 196 | { |
| 197 | struct resource *resource; |
Felix Held | f2ec648 | 2018-07-27 02:31:09 +0200 | [diff] [blame] | 198 | unsigned int bit; |
Li-Ta Lo | 75337f7 | 2004-05-07 21:56:48 +0000 | [diff] [blame] | 199 | |
Felix Held | f2ec648 | 2018-07-27 02:31:09 +0200 | [diff] [blame] | 200 | /* If none of the mask bits is set, the resource would occupy the whole |
| 201 | IO space leading to IO resource conflicts with the other devices */ |
Samuel Holland | 7daac91 | 2017-06-06 22:55:01 -0500 | [diff] [blame] | 202 | if (!mask) { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 203 | printk(BIOS_ERR, "device %s index %d has no mask.\n", |
Stefan Reinauer | aeead27 | 2011-01-31 21:16:48 +0000 | [diff] [blame] | 204 | dev_path(dev), index); |
| 205 | return; |
| 206 | } |
| 207 | |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 208 | resource = new_resource(dev, index); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 209 | resource->flags |= IORESOURCE_IO; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 210 | |
Felix Held | f2ec648 | 2018-07-27 02:31:09 +0200 | [diff] [blame] | 211 | /* Calculate IO region size which is determined by the first one from |
| 212 | the LSB of the mask. */ |
| 213 | for (bit = 0; bit <= 15 && (mask & (1 << bit)) == 0; ++bit) |
| 214 | ; |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 215 | |
Felix Held | f2ec648 | 2018-07-27 02:31:09 +0200 | [diff] [blame] | 216 | resource->gran = bit; |
| 217 | resource->align = bit; |
| 218 | resource->size = 1 << bit; |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 219 | |
Felix Held | f2ec648 | 2018-07-27 02:31:09 +0200 | [diff] [blame] | 220 | /* Calculate IO region address limit which is determined by the first |
| 221 | one from the MSB of the mask. */ |
| 222 | for (bit = 15; bit != 0 && (mask & (1 << bit)) == 0; --bit) |
| 223 | ; |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 224 | |
Felix Held | f2ec648 | 2018-07-27 02:31:09 +0200 | [diff] [blame] | 225 | resource->limit = (1 << (bit + 1)) - 1; |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 226 | |
Felix Held | f2ec648 | 2018-07-27 02:31:09 +0200 | [diff] [blame] | 227 | /* The block of ones in the mask is expected to be continuous. |
Martin Roth | 0949e73 | 2021-10-01 14:28:22 -0600 | [diff] [blame] | 228 | If there is any zero in between the block of ones, it is ignored |
Felix Held | f2ec648 | 2018-07-27 02:31:09 +0200 | [diff] [blame] | 229 | in the calculation of the resource size and limit. */ |
| 230 | if (mask != (resource->limit ^ (resource->size - 1))) |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 231 | printk(BIOS_WARNING, "mask of device %s index %d is wrong.\n", |
Felix Held | f2ec648 | 2018-07-27 02:31:09 +0200 | [diff] [blame] | 232 | dev_path(dev), index); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 233 | } |
| 234 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 235 | static void get_resources(struct device *dev, struct pnp_info *info) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 236 | { |
| 237 | struct resource *resource; |
| 238 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 239 | if (info->flags & PNP_IO0) |
Samuel Holland | 7daac91 | 2017-06-06 22:55:01 -0500 | [diff] [blame] | 240 | pnp_get_ioresource(dev, PNP_IDX_IO0, info->io0); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 241 | if (info->flags & PNP_IO1) |
Samuel Holland | 7daac91 | 2017-06-06 22:55:01 -0500 | [diff] [blame] | 242 | pnp_get_ioresource(dev, PNP_IDX_IO1, info->io1); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 243 | if (info->flags & PNP_IO2) |
Samuel Holland | 7daac91 | 2017-06-06 22:55:01 -0500 | [diff] [blame] | 244 | pnp_get_ioresource(dev, PNP_IDX_IO2, info->io2); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 245 | if (info->flags & PNP_IO3) |
Samuel Holland | 7daac91 | 2017-06-06 22:55:01 -0500 | [diff] [blame] | 246 | pnp_get_ioresource(dev, PNP_IDX_IO3, info->io3); |
Michael Niewöhner | 6e016f0 | 2020-12-26 22:20:49 +0100 | [diff] [blame] | 247 | if (info->flags & PNP_IO4) |
| 248 | pnp_get_ioresource(dev, PNP_IDX_IO4, info->io4); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 249 | |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 250 | if (info->flags & PNP_IRQ0) { |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 251 | resource = new_resource(dev, PNP_IDX_IRQ0); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 252 | resource->size = 1; |
| 253 | resource->flags |= IORESOURCE_IRQ; |
| 254 | } |
| 255 | if (info->flags & PNP_IRQ1) { |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 256 | resource = new_resource(dev, PNP_IDX_IRQ1); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 257 | resource->size = 1; |
| 258 | resource->flags |= IORESOURCE_IRQ; |
| 259 | } |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 260 | |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 261 | if (info->flags & PNP_DRQ0) { |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 262 | resource = new_resource(dev, PNP_IDX_DRQ0); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 263 | resource->size = 1; |
| 264 | resource->flags |= IORESOURCE_DRQ; |
| 265 | } |
| 266 | if (info->flags & PNP_DRQ1) { |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 267 | resource = new_resource(dev, PNP_IDX_DRQ1); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 268 | resource->size = 1; |
| 269 | resource->flags |= IORESOURCE_DRQ; |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 270 | } |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 271 | |
| 272 | /* |
| 273 | * These are not IRQs, but set the flag to have the |
| 274 | * resource allocator do the right thing. |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 275 | */ |
| 276 | if (info->flags & PNP_EN) { |
| 277 | resource = new_resource(dev, PNP_IDX_EN); |
| 278 | resource->size = 1; |
| 279 | resource->flags |= IORESOURCE_IRQ; |
| 280 | } |
| 281 | if (info->flags & PNP_MSC0) { |
| 282 | resource = new_resource(dev, PNP_IDX_MSC0); |
| 283 | resource->size = 1; |
| 284 | resource->flags |= IORESOURCE_IRQ; |
| 285 | } |
| 286 | if (info->flags & PNP_MSC1) { |
| 287 | resource = new_resource(dev, PNP_IDX_MSC1); |
| 288 | resource->size = 1; |
| 289 | resource->flags |= IORESOURCE_IRQ; |
| 290 | } |
Damien Zammit | 62c0276 | 2015-12-28 23:04:47 +1100 | [diff] [blame] | 291 | if (info->flags & PNP_MSC2) { |
| 292 | resource = new_resource(dev, PNP_IDX_MSC2); |
| 293 | resource->size = 1; |
| 294 | resource->flags |= IORESOURCE_IRQ; |
| 295 | } |
| 296 | if (info->flags & PNP_MSC3) { |
| 297 | resource = new_resource(dev, PNP_IDX_MSC3); |
| 298 | resource->size = 1; |
| 299 | resource->flags |= IORESOURCE_IRQ; |
| 300 | } |
Stefan Reinauer | 0108b93 | 2013-12-11 11:06:08 -0800 | [diff] [blame] | 301 | if (info->flags & PNP_MSC4) { |
| 302 | resource = new_resource(dev, PNP_IDX_MSC4); |
| 303 | resource->size = 1; |
| 304 | resource->flags |= IORESOURCE_IRQ; |
| 305 | } |
Damien Zammit | 62c0276 | 2015-12-28 23:04:47 +1100 | [diff] [blame] | 306 | if (info->flags & PNP_MSC5) { |
| 307 | resource = new_resource(dev, PNP_IDX_MSC5); |
| 308 | resource->size = 1; |
| 309 | resource->flags |= IORESOURCE_IRQ; |
| 310 | } |
| 311 | if (info->flags & PNP_MSC6) { |
| 312 | resource = new_resource(dev, PNP_IDX_MSC6); |
| 313 | resource->size = 1; |
| 314 | resource->flags |= IORESOURCE_IRQ; |
| 315 | } |
| 316 | if (info->flags & PNP_MSC7) { |
| 317 | resource = new_resource(dev, PNP_IDX_MSC7); |
| 318 | resource->size = 1; |
| 319 | resource->flags |= IORESOURCE_IRQ; |
| 320 | } |
| 321 | if (info->flags & PNP_MSC8) { |
| 322 | resource = new_resource(dev, PNP_IDX_MSC8); |
| 323 | resource->size = 1; |
| 324 | resource->flags |= IORESOURCE_IRQ; |
| 325 | } |
| 326 | if (info->flags & PNP_MSC9) { |
| 327 | resource = new_resource(dev, PNP_IDX_MSC9); |
| 328 | resource->size = 1; |
| 329 | resource->flags |= IORESOURCE_IRQ; |
| 330 | } |
| 331 | if (info->flags & PNP_MSCA) { |
| 332 | resource = new_resource(dev, PNP_IDX_MSCA); |
| 333 | resource->size = 1; |
| 334 | resource->flags |= IORESOURCE_IRQ; |
| 335 | } |
| 336 | if (info->flags & PNP_MSCB) { |
| 337 | resource = new_resource(dev, PNP_IDX_MSCB); |
| 338 | resource->size = 1; |
| 339 | resource->flags |= IORESOURCE_IRQ; |
| 340 | } |
| 341 | if (info->flags & PNP_MSCC) { |
| 342 | resource = new_resource(dev, PNP_IDX_MSCC); |
| 343 | resource->size = 1; |
| 344 | resource->flags |= IORESOURCE_IRQ; |
| 345 | } |
| 346 | if (info->flags & PNP_MSCD) { |
| 347 | resource = new_resource(dev, PNP_IDX_MSCD); |
| 348 | resource->size = 1; |
| 349 | resource->flags |= IORESOURCE_IRQ; |
| 350 | } |
| 351 | if (info->flags & PNP_MSCE) { |
| 352 | resource = new_resource(dev, PNP_IDX_MSCE); |
Stefan Reinauer | 08ba7d0 | 2013-10-31 15:58:50 -0700 | [diff] [blame] | 353 | resource->size = 1; |
| 354 | resource->flags |= IORESOURCE_IRQ; |
| 355 | } |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 356 | } |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 357 | |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 358 | void pnp_enable_devices(struct device *base_dev, struct device_operations *ops, |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 359 | unsigned int functions, struct pnp_info *info) |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 360 | { |
| 361 | struct device_path path; |
Elyes HAOUAS | b77cf62 | 2018-05-02 21:01:18 +0200 | [diff] [blame] | 362 | struct device *dev; |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 363 | int i; |
| 364 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 365 | path.type = DEVICE_PATH_PNP; |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 366 | path.pnp.port = base_dev->path.pnp.port; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 367 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 368 | /* Setup the ops and resources on the newly allocated devices. */ |
| 369 | for (i = 0; i < functions; i++) { |
Uwe Hermann | aa4bedf | 2007-07-12 13:12:47 +0000 | [diff] [blame] | 370 | /* Skip logical devices this Super I/O doesn't have. */ |
Felix Held | 7b7bc59 | 2019-12-15 13:53:48 +0100 | [diff] [blame] | 371 | if (info[i].function == PNP_SKIP_FUNCTION) |
Uwe Hermann | aa4bedf | 2007-07-12 13:12:47 +0000 | [diff] [blame] | 372 | continue; |
| 373 | |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 374 | path.pnp.device = info[i].function; |
Arthur Heymans | 7fcd4d5 | 2023-08-24 15:12:19 +0200 | [diff] [blame] | 375 | dev = alloc_find_dev(base_dev->upstream, &path); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 376 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 377 | /* Don't initialize a device multiple times. */ |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 378 | if (dev->ops) |
Eric Biederman | 7003ba4 | 2004-10-16 06:20:29 +0000 | [diff] [blame] | 379 | continue; |
Li-Ta Lo | c6bcedb | 2004-04-21 16:57:05 +0000 | [diff] [blame] | 380 | |
Felix Held | 745e58a | 2018-07-06 19:38:24 +0200 | [diff] [blame] | 381 | /* use LDN-specific ops override from corresponding pnp_info |
| 382 | entry if not NULL */ |
| 383 | if (info[i].ops) |
Li-Ta Lo | 75337f7 | 2004-05-07 21:56:48 +0000 | [diff] [blame] | 384 | dev->ops = info[i].ops; |
Felix Held | 745e58a | 2018-07-06 19:38:24 +0200 | [diff] [blame] | 385 | /* else use device ops */ |
| 386 | else |
| 387 | dev->ops = ops; |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 388 | |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 389 | get_resources(dev, &info[i]); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 390 | } |
| 391 | } |