aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/resource.c
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2015-02-01 21:42:51 -0500
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2015-02-03 16:27:18 -0500
commiteb76d55e66a9bed2359cc5a0f08168b287c4dea8 (patch)
tree37ec97d7eb91db5cd859fdec2a00d52bc139a11e /drivers/acpi/resource.c
parente814f6deee6188265b5af9f1190e5734f116860e (diff)
ACPI: Unify the parsing of address_space and ext_address_space
With the unions in place which let us identify the substructs we can use a single parser for address_space and ext_address_space. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Jiang Liu <jiang.liu@linux.intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/acpi/resource.c')
-rw-r--r--drivers/acpi/resource.c90
1 files changed, 34 insertions, 56 deletions
diff --git a/drivers/acpi/resource.c b/drivers/acpi/resource.c
index cdb1a3c4a0b9..99903d196024 100644
--- a/drivers/acpi/resource.c
+++ b/drivers/acpi/resource.c
@@ -178,6 +178,35 @@ bool acpi_dev_resource_io(struct acpi_resource *ares, struct resource *res)
178} 178}
179EXPORT_SYMBOL_GPL(acpi_dev_resource_io); 179EXPORT_SYMBOL_GPL(acpi_dev_resource_io);
180 180
181static bool acpi_decode_space(struct resource *res,
182 struct acpi_resource_address *addr,
183 struct acpi_address64_attribute *attr)
184{
185 u8 iodec = attr->granularity == 0xfff ? ACPI_DECODE_10 : ACPI_DECODE_16;
186 bool window = addr->producer_consumer == ACPI_PRODUCER;
187 bool wp = addr->info.mem.write_protect;
188 u64 len = attr->address_length;
189
190 res->start = attr->minimum;
191 res->end = attr->maximum;
192
193 switch (addr->resource_type) {
194 case ACPI_MEMORY_RANGE:
195 acpi_dev_memresource_flags(res, len, wp, window);
196 break;
197 case ACPI_IO_RANGE:
198 acpi_dev_ioresource_flags(res, len, iodec, window);
199 break;
200 case ACPI_BUS_NUMBER_RANGE:
201 res->flags = IORESOURCE_BUS;
202 break;
203 default:
204 return false;
205 }
206
207 return !(res->flags & IORESOURCE_DISABLED);
208}
209
181/** 210/**
182 * acpi_dev_resource_address_space - Extract ACPI address space information. 211 * acpi_dev_resource_address_space - Extract ACPI address space information.
183 * @ares: Input ACPI resource object. 212 * @ares: Input ACPI resource object.
@@ -190,39 +219,13 @@ EXPORT_SYMBOL_GPL(acpi_dev_resource_io);
190bool acpi_dev_resource_address_space(struct acpi_resource *ares, 219bool acpi_dev_resource_address_space(struct acpi_resource *ares,
191 struct resource *res) 220 struct resource *res)
192{ 221{
193 acpi_status status;
194 struct acpi_resource_address64 addr; 222 struct acpi_resource_address64 addr;
195 bool window;
196 u8 io_decode;
197
198 status = acpi_resource_to_address64(ares, &addr);
199 if (ACPI_FAILURE(status))
200 return false;
201 223
202 res->start = addr.address.minimum; 224 if (ACPI_FAILURE(acpi_resource_to_address64(ares, &addr)))
203 res->end = addr.address.maximum;
204 window = addr.producer_consumer == ACPI_PRODUCER;
205
206 switch(addr.resource_type) {
207 case ACPI_MEMORY_RANGE:
208 acpi_dev_memresource_flags(res, addr.address.address_length,
209 addr.info.mem.write_protect,
210 window);
211 break;
212 case ACPI_IO_RANGE:
213 io_decode = addr.address.granularity == 0xfff ?
214 ACPI_DECODE_10 : ACPI_DECODE_16;
215 acpi_dev_ioresource_flags(res, addr.address.address_length,
216 io_decode, window);
217 break;
218 case ACPI_BUS_NUMBER_RANGE:
219 res->flags = IORESOURCE_BUS;
220 break;
221 default:
222 return false; 225 return false;
223 }
224 226
225 return !(res->flags & IORESOURCE_DISABLED); 227 return acpi_decode_space(res, (struct acpi_resource_address *)&addr,
228 &addr.address);
226} 229}
227EXPORT_SYMBOL_GPL(acpi_dev_resource_address_space); 230EXPORT_SYMBOL_GPL(acpi_dev_resource_address_space);
228 231
@@ -239,39 +242,14 @@ bool acpi_dev_resource_ext_address_space(struct acpi_resource *ares,
239 struct resource *res) 242 struct resource *res)
240{ 243{
241 struct acpi_resource_extended_address64 *ext_addr; 244 struct acpi_resource_extended_address64 *ext_addr;
242 bool window;
243 u8 io_decode;
244 245
245 if (ares->type != ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64) 246 if (ares->type != ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64)
246 return false; 247 return false;
247 248
248 ext_addr = &ares->data.ext_address64; 249 ext_addr = &ares->data.ext_address64;
249 250
250 res->start = ext_addr->address.minimum; 251 return acpi_decode_space(res, (struct acpi_resource_address *)ext_addr,
251 res->end = ext_addr->address.maximum; 252 &ext_addr->address);
252 window = ext_addr->producer_consumer == ACPI_PRODUCER;
253
254 switch(ext_addr->resource_type) {
255 case ACPI_MEMORY_RANGE:
256 acpi_dev_memresource_flags(res,
257 ext_addr->address.address_length,
258 ext_addr->info.mem.write_protect,
259 window);
260 break;
261 case ACPI_IO_RANGE:
262 io_decode = ext_addr->address.granularity == 0xfff ?
263 ACPI_DECODE_10 : ACPI_DECODE_16;
264 acpi_dev_ioresource_flags(res, ext_addr->address.address_length,
265 io_decode, window);
266 break;
267 case ACPI_BUS_NUMBER_RANGE:
268 res->flags = IORESOURCE_BUS;
269 break;
270 default:
271 return false;
272 }
273
274 return !(res->flags & IORESOURCE_DISABLED);
275} 253}
276EXPORT_SYMBOL_GPL(acpi_dev_resource_ext_address_space); 254EXPORT_SYMBOL_GPL(acpi_dev_resource_ext_address_space);
277 255