resource.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. /*
  2. * drivers/acpi/resource.c - ACPI device resources interpretation.
  3. *
  4. * Copyright (C) 2012, Intel Corp.
  5. * Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  6. *
  7. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as published
  11. * by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  19. */
  20. #include <linux/acpi.h>
  21. #include <linux/device.h>
  22. #include <linux/export.h>
  23. #include <linux/ioport.h>
  24. #include <linux/slab.h>
  25. #ifdef CONFIG_X86
  26. #define valid_IRQ(i) (((i) != 0) && ((i) != 2))
  27. static inline bool acpi_iospace_resource_valid(struct resource *res)
  28. {
  29. /* On X86 IO space is limited to the [0 - 64K] IO port range */
  30. return res->end < 0x10003;
  31. }
  32. #else
  33. #define valid_IRQ(i) (true)
  34. /*
  35. * ACPI IO descriptors on arches other than X86 contain MMIO CPU physical
  36. * addresses mapping IO space in CPU physical address space, IO space
  37. * resources can be placed anywhere in the 64-bit physical address space.
  38. */
  39. static inline bool
  40. acpi_iospace_resource_valid(struct resource *res) { return true; }
  41. #endif
  42. static bool acpi_dev_resource_len_valid(u64 start, u64 end, u64 len, bool io)
  43. {
  44. u64 reslen = end - start + 1;
  45. /*
  46. * CHECKME: len might be required to check versus a minimum
  47. * length as well. 1 for io is fine, but for memory it does
  48. * not make any sense at all.
  49. * Note: some BIOSes report incorrect length for ACPI address space
  50. * descriptor, so remove check of 'reslen == len' to avoid regression.
  51. */
  52. if (len && reslen && start <= end)
  53. return true;
  54. pr_debug("ACPI: invalid or unassigned resource %s [%016llx - %016llx] length [%016llx]\n",
  55. io ? "io" : "mem", start, end, len);
  56. return false;
  57. }
  58. static void acpi_dev_memresource_flags(struct resource *res, u64 len,
  59. u8 write_protect)
  60. {
  61. res->flags = IORESOURCE_MEM;
  62. if (!acpi_dev_resource_len_valid(res->start, res->end, len, false))
  63. res->flags |= IORESOURCE_DISABLED | IORESOURCE_UNSET;
  64. if (write_protect == ACPI_READ_WRITE_MEMORY)
  65. res->flags |= IORESOURCE_MEM_WRITEABLE;
  66. }
  67. static void acpi_dev_get_memresource(struct resource *res, u64 start, u64 len,
  68. u8 write_protect)
  69. {
  70. res->start = start;
  71. res->end = start + len - 1;
  72. acpi_dev_memresource_flags(res, len, write_protect);
  73. }
  74. /**
  75. * acpi_dev_resource_memory - Extract ACPI memory resource information.
  76. * @ares: Input ACPI resource object.
  77. * @res: Output generic resource object.
  78. *
  79. * Check if the given ACPI resource object represents a memory resource and
  80. * if that's the case, use the information in it to populate the generic
  81. * resource object pointed to by @res.
  82. *
  83. * Return:
  84. * 1) false with res->flags setting to zero: not the expected resource type
  85. * 2) false with IORESOURCE_DISABLED in res->flags: valid unassigned resource
  86. * 3) true: valid assigned resource
  87. */
  88. bool acpi_dev_resource_memory(struct acpi_resource *ares, struct resource *res)
  89. {
  90. struct acpi_resource_memory24 *memory24;
  91. struct acpi_resource_memory32 *memory32;
  92. struct acpi_resource_fixed_memory32 *fixed_memory32;
  93. switch (ares->type) {
  94. case ACPI_RESOURCE_TYPE_MEMORY24:
  95. memory24 = &ares->data.memory24;
  96. acpi_dev_get_memresource(res, memory24->minimum << 8,
  97. memory24->address_length << 8,
  98. memory24->write_protect);
  99. break;
  100. case ACPI_RESOURCE_TYPE_MEMORY32:
  101. memory32 = &ares->data.memory32;
  102. acpi_dev_get_memresource(res, memory32->minimum,
  103. memory32->address_length,
  104. memory32->write_protect);
  105. break;
  106. case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
  107. fixed_memory32 = &ares->data.fixed_memory32;
  108. acpi_dev_get_memresource(res, fixed_memory32->address,
  109. fixed_memory32->address_length,
  110. fixed_memory32->write_protect);
  111. break;
  112. default:
  113. res->flags = 0;
  114. return false;
  115. }
  116. return !(res->flags & IORESOURCE_DISABLED);
  117. }
  118. EXPORT_SYMBOL_GPL(acpi_dev_resource_memory);
  119. static void acpi_dev_ioresource_flags(struct resource *res, u64 len,
  120. u8 io_decode, u8 translation_type)
  121. {
  122. res->flags = IORESOURCE_IO;
  123. if (!acpi_dev_resource_len_valid(res->start, res->end, len, true))
  124. res->flags |= IORESOURCE_DISABLED | IORESOURCE_UNSET;
  125. if (!acpi_iospace_resource_valid(res))
  126. res->flags |= IORESOURCE_DISABLED | IORESOURCE_UNSET;
  127. if (io_decode == ACPI_DECODE_16)
  128. res->flags |= IORESOURCE_IO_16BIT_ADDR;
  129. if (translation_type == ACPI_SPARSE_TRANSLATION)
  130. res->flags |= IORESOURCE_IO_SPARSE;
  131. }
  132. static void acpi_dev_get_ioresource(struct resource *res, u64 start, u64 len,
  133. u8 io_decode)
  134. {
  135. res->start = start;
  136. res->end = start + len - 1;
  137. acpi_dev_ioresource_flags(res, len, io_decode, 0);
  138. }
  139. /**
  140. * acpi_dev_resource_io - Extract ACPI I/O resource information.
  141. * @ares: Input ACPI resource object.
  142. * @res: Output generic resource object.
  143. *
  144. * Check if the given ACPI resource object represents an I/O resource and
  145. * if that's the case, use the information in it to populate the generic
  146. * resource object pointed to by @res.
  147. *
  148. * Return:
  149. * 1) false with res->flags setting to zero: not the expected resource type
  150. * 2) false with IORESOURCE_DISABLED in res->flags: valid unassigned resource
  151. * 3) true: valid assigned resource
  152. */
  153. bool acpi_dev_resource_io(struct acpi_resource *ares, struct resource *res)
  154. {
  155. struct acpi_resource_io *io;
  156. struct acpi_resource_fixed_io *fixed_io;
  157. switch (ares->type) {
  158. case ACPI_RESOURCE_TYPE_IO:
  159. io = &ares->data.io;
  160. acpi_dev_get_ioresource(res, io->minimum,
  161. io->address_length,
  162. io->io_decode);
  163. break;
  164. case ACPI_RESOURCE_TYPE_FIXED_IO:
  165. fixed_io = &ares->data.fixed_io;
  166. acpi_dev_get_ioresource(res, fixed_io->address,
  167. fixed_io->address_length,
  168. ACPI_DECODE_10);
  169. break;
  170. default:
  171. res->flags = 0;
  172. return false;
  173. }
  174. return !(res->flags & IORESOURCE_DISABLED);
  175. }
  176. EXPORT_SYMBOL_GPL(acpi_dev_resource_io);
  177. static bool acpi_decode_space(struct resource_win *win,
  178. struct acpi_resource_address *addr,
  179. struct acpi_address64_attribute *attr)
  180. {
  181. u8 iodec = attr->granularity == 0xfff ? ACPI_DECODE_10 : ACPI_DECODE_16;
  182. bool wp = addr->info.mem.write_protect;
  183. u64 len = attr->address_length;
  184. u64 start, end, offset = 0;
  185. struct resource *res = &win->res;
  186. /*
  187. * Filter out invalid descriptor according to ACPI Spec 5.0, section
  188. * 6.4.3.5 Address Space Resource Descriptors.
  189. */
  190. if ((addr->min_address_fixed != addr->max_address_fixed && len) ||
  191. (addr->min_address_fixed && addr->max_address_fixed && !len))
  192. pr_debug("ACPI: Invalid address space min_addr_fix %d, max_addr_fix %d, len %llx\n",
  193. addr->min_address_fixed, addr->max_address_fixed, len);
  194. /*
  195. * For bridges that translate addresses across the bridge,
  196. * translation_offset is the offset that must be added to the
  197. * address on the secondary side to obtain the address on the
  198. * primary side. Non-bridge devices must list 0 for all Address
  199. * Translation offset bits.
  200. */
  201. if (addr->producer_consumer == ACPI_PRODUCER)
  202. offset = attr->translation_offset;
  203. else if (attr->translation_offset)
  204. pr_debug("ACPI: translation_offset(%lld) is invalid for non-bridge device.\n",
  205. attr->translation_offset);
  206. start = attr->minimum + offset;
  207. end = attr->maximum + offset;
  208. win->offset = offset;
  209. res->start = start;
  210. res->end = end;
  211. if (sizeof(resource_size_t) < sizeof(u64) &&
  212. (offset != win->offset || start != res->start || end != res->end)) {
  213. pr_warn("acpi resource window ([%#llx-%#llx] ignored, not CPU addressable)\n",
  214. attr->minimum, attr->maximum);
  215. return false;
  216. }
  217. switch (addr->resource_type) {
  218. case ACPI_MEMORY_RANGE:
  219. acpi_dev_memresource_flags(res, len, wp);
  220. break;
  221. case ACPI_IO_RANGE:
  222. acpi_dev_ioresource_flags(res, len, iodec,
  223. addr->info.io.translation_type);
  224. break;
  225. case ACPI_BUS_NUMBER_RANGE:
  226. res->flags = IORESOURCE_BUS;
  227. break;
  228. default:
  229. return false;
  230. }
  231. if (addr->producer_consumer == ACPI_PRODUCER)
  232. res->flags |= IORESOURCE_WINDOW;
  233. if (addr->info.mem.caching == ACPI_PREFETCHABLE_MEMORY)
  234. res->flags |= IORESOURCE_PREFETCH;
  235. return !(res->flags & IORESOURCE_DISABLED);
  236. }
  237. /**
  238. * acpi_dev_resource_address_space - Extract ACPI address space information.
  239. * @ares: Input ACPI resource object.
  240. * @win: Output generic resource object.
  241. *
  242. * Check if the given ACPI resource object represents an address space resource
  243. * and if that's the case, use the information in it to populate the generic
  244. * resource object pointed to by @win.
  245. *
  246. * Return:
  247. * 1) false with win->res.flags setting to zero: not the expected resource type
  248. * 2) false with IORESOURCE_DISABLED in win->res.flags: valid unassigned
  249. * resource
  250. * 3) true: valid assigned resource
  251. */
  252. bool acpi_dev_resource_address_space(struct acpi_resource *ares,
  253. struct resource_win *win)
  254. {
  255. struct acpi_resource_address64 addr;
  256. win->res.flags = 0;
  257. if (ACPI_FAILURE(acpi_resource_to_address64(ares, &addr)))
  258. return false;
  259. return acpi_decode_space(win, (struct acpi_resource_address *)&addr,
  260. &addr.address);
  261. }
  262. EXPORT_SYMBOL_GPL(acpi_dev_resource_address_space);
  263. /**
  264. * acpi_dev_resource_ext_address_space - Extract ACPI address space information.
  265. * @ares: Input ACPI resource object.
  266. * @win: Output generic resource object.
  267. *
  268. * Check if the given ACPI resource object represents an extended address space
  269. * resource and if that's the case, use the information in it to populate the
  270. * generic resource object pointed to by @win.
  271. *
  272. * Return:
  273. * 1) false with win->res.flags setting to zero: not the expected resource type
  274. * 2) false with IORESOURCE_DISABLED in win->res.flags: valid unassigned
  275. * resource
  276. * 3) true: valid assigned resource
  277. */
  278. bool acpi_dev_resource_ext_address_space(struct acpi_resource *ares,
  279. struct resource_win *win)
  280. {
  281. struct acpi_resource_extended_address64 *ext_addr;
  282. win->res.flags = 0;
  283. if (ares->type != ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64)
  284. return false;
  285. ext_addr = &ares->data.ext_address64;
  286. return acpi_decode_space(win, (struct acpi_resource_address *)ext_addr,
  287. &ext_addr->address);
  288. }
  289. EXPORT_SYMBOL_GPL(acpi_dev_resource_ext_address_space);
  290. /**
  291. * acpi_dev_irq_flags - Determine IRQ resource flags.
  292. * @triggering: Triggering type as provided by ACPI.
  293. * @polarity: Interrupt polarity as provided by ACPI.
  294. * @shareable: Whether or not the interrupt is shareable.
  295. */
  296. unsigned long acpi_dev_irq_flags(u8 triggering, u8 polarity, u8 shareable)
  297. {
  298. unsigned long flags;
  299. if (triggering == ACPI_LEVEL_SENSITIVE)
  300. flags = polarity == ACPI_ACTIVE_LOW ?
  301. IORESOURCE_IRQ_LOWLEVEL : IORESOURCE_IRQ_HIGHLEVEL;
  302. else
  303. flags = polarity == ACPI_ACTIVE_LOW ?
  304. IORESOURCE_IRQ_LOWEDGE : IORESOURCE_IRQ_HIGHEDGE;
  305. if (shareable == ACPI_SHARED)
  306. flags |= IORESOURCE_IRQ_SHAREABLE;
  307. return flags | IORESOURCE_IRQ;
  308. }
  309. EXPORT_SYMBOL_GPL(acpi_dev_irq_flags);
  310. static void acpi_dev_irqresource_disabled(struct resource *res, u32 gsi)
  311. {
  312. res->start = gsi;
  313. res->end = gsi;
  314. res->flags = IORESOURCE_IRQ | IORESOURCE_DISABLED | IORESOURCE_UNSET;
  315. }
  316. static void acpi_dev_get_irqresource(struct resource *res, u32 gsi,
  317. u8 triggering, u8 polarity, u8 shareable,
  318. bool legacy)
  319. {
  320. int irq, p, t;
  321. if (!valid_IRQ(gsi)) {
  322. acpi_dev_irqresource_disabled(res, gsi);
  323. return;
  324. }
  325. /*
  326. * In IO-APIC mode, use overrided attribute. Two reasons:
  327. * 1. BIOS bug in DSDT
  328. * 2. BIOS uses IO-APIC mode Interrupt Source Override
  329. *
  330. * We do this only if we are dealing with IRQ() or IRQNoFlags()
  331. * resource (the legacy ISA resources). With modern ACPI 5 devices
  332. * using extended IRQ descriptors we take the IRQ configuration
  333. * from _CRS directly.
  334. */
  335. if (legacy && !acpi_get_override_irq(gsi, &t, &p)) {
  336. u8 trig = t ? ACPI_LEVEL_SENSITIVE : ACPI_EDGE_SENSITIVE;
  337. u8 pol = p ? ACPI_ACTIVE_LOW : ACPI_ACTIVE_HIGH;
  338. if (triggering != trig || polarity != pol) {
  339. pr_warning("ACPI: IRQ %d override to %s, %s\n", gsi,
  340. t ? "level" : "edge", p ? "low" : "high");
  341. triggering = trig;
  342. polarity = pol;
  343. }
  344. }
  345. res->flags = acpi_dev_irq_flags(triggering, polarity, shareable);
  346. irq = acpi_register_gsi(NULL, gsi, triggering, polarity);
  347. if (irq >= 0) {
  348. res->start = irq;
  349. res->end = irq;
  350. } else {
  351. acpi_dev_irqresource_disabled(res, gsi);
  352. }
  353. }
  354. /**
  355. * acpi_dev_resource_interrupt - Extract ACPI interrupt resource information.
  356. * @ares: Input ACPI resource object.
  357. * @index: Index into the array of GSIs represented by the resource.
  358. * @res: Output generic resource object.
  359. *
  360. * Check if the given ACPI resource object represents an interrupt resource
  361. * and @index does not exceed the resource's interrupt count (true is returned
  362. * in that case regardless of the results of the other checks)). If that's the
  363. * case, register the GSI corresponding to @index from the array of interrupts
  364. * represented by the resource and populate the generic resource object pointed
  365. * to by @res accordingly. If the registration of the GSI is not successful,
  366. * IORESOURCE_DISABLED will be set it that object's flags.
  367. *
  368. * Return:
  369. * 1) false with res->flags setting to zero: not the expected resource type
  370. * 2) false with IORESOURCE_DISABLED in res->flags: valid unassigned resource
  371. * 3) true: valid assigned resource
  372. */
  373. bool acpi_dev_resource_interrupt(struct acpi_resource *ares, int index,
  374. struct resource *res)
  375. {
  376. struct acpi_resource_irq *irq;
  377. struct acpi_resource_extended_irq *ext_irq;
  378. switch (ares->type) {
  379. case ACPI_RESOURCE_TYPE_IRQ:
  380. /*
  381. * Per spec, only one interrupt per descriptor is allowed in
  382. * _CRS, but some firmware violates this, so parse them all.
  383. */
  384. irq = &ares->data.irq;
  385. if (index >= irq->interrupt_count) {
  386. acpi_dev_irqresource_disabled(res, 0);
  387. return false;
  388. }
  389. acpi_dev_get_irqresource(res, irq->interrupts[index],
  390. irq->triggering, irq->polarity,
  391. irq->sharable, true);
  392. break;
  393. case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
  394. ext_irq = &ares->data.extended_irq;
  395. if (index >= ext_irq->interrupt_count) {
  396. acpi_dev_irqresource_disabled(res, 0);
  397. return false;
  398. }
  399. acpi_dev_get_irqresource(res, ext_irq->interrupts[index],
  400. ext_irq->triggering, ext_irq->polarity,
  401. ext_irq->sharable, false);
  402. break;
  403. default:
  404. res->flags = 0;
  405. return false;
  406. }
  407. return true;
  408. }
  409. EXPORT_SYMBOL_GPL(acpi_dev_resource_interrupt);
  410. /**
  411. * acpi_dev_free_resource_list - Free resource from %acpi_dev_get_resources().
  412. * @list: The head of the resource list to free.
  413. */
  414. void acpi_dev_free_resource_list(struct list_head *list)
  415. {
  416. resource_list_free(list);
  417. }
  418. EXPORT_SYMBOL_GPL(acpi_dev_free_resource_list);
  419. struct res_proc_context {
  420. struct list_head *list;
  421. int (*preproc)(struct acpi_resource *, void *);
  422. void *preproc_data;
  423. int count;
  424. int error;
  425. };
  426. static acpi_status acpi_dev_new_resource_entry(struct resource_win *win,
  427. struct res_proc_context *c)
  428. {
  429. struct resource_entry *rentry;
  430. rentry = resource_list_create_entry(NULL, 0);
  431. if (!rentry) {
  432. c->error = -ENOMEM;
  433. return AE_NO_MEMORY;
  434. }
  435. *rentry->res = win->res;
  436. rentry->offset = win->offset;
  437. resource_list_add_tail(rentry, c->list);
  438. c->count++;
  439. return AE_OK;
  440. }
  441. static acpi_status acpi_dev_process_resource(struct acpi_resource *ares,
  442. void *context)
  443. {
  444. struct res_proc_context *c = context;
  445. struct resource_win win;
  446. struct resource *res = &win.res;
  447. int i;
  448. if (c->preproc) {
  449. int ret;
  450. ret = c->preproc(ares, c->preproc_data);
  451. if (ret < 0) {
  452. c->error = ret;
  453. return AE_CTRL_TERMINATE;
  454. } else if (ret > 0) {
  455. return AE_OK;
  456. }
  457. }
  458. memset(&win, 0, sizeof(win));
  459. if (acpi_dev_resource_memory(ares, res)
  460. || acpi_dev_resource_io(ares, res)
  461. || acpi_dev_resource_address_space(ares, &win)
  462. || acpi_dev_resource_ext_address_space(ares, &win))
  463. return acpi_dev_new_resource_entry(&win, c);
  464. for (i = 0; acpi_dev_resource_interrupt(ares, i, res); i++) {
  465. acpi_status status;
  466. status = acpi_dev_new_resource_entry(&win, c);
  467. if (ACPI_FAILURE(status))
  468. return status;
  469. }
  470. return AE_OK;
  471. }
  472. /**
  473. * acpi_dev_get_resources - Get current resources of a device.
  474. * @adev: ACPI device node to get the resources for.
  475. * @list: Head of the resultant list of resources (must be empty).
  476. * @preproc: The caller's preprocessing routine.
  477. * @preproc_data: Pointer passed to the caller's preprocessing routine.
  478. *
  479. * Evaluate the _CRS method for the given device node and process its output by
  480. * (1) executing the @preproc() rountine provided by the caller, passing the
  481. * resource pointer and @preproc_data to it as arguments, for each ACPI resource
  482. * returned and (2) converting all of the returned ACPI resources into struct
  483. * resource objects if possible. If the return value of @preproc() in step (1)
  484. * is different from 0, step (2) is not applied to the given ACPI resource and
  485. * if that value is negative, the whole processing is aborted and that value is
  486. * returned as the final error code.
  487. *
  488. * The resultant struct resource objects are put on the list pointed to by
  489. * @list, that must be empty initially, as members of struct resource_entry
  490. * objects. Callers of this routine should use %acpi_dev_free_resource_list() to
  491. * free that list.
  492. *
  493. * The number of resources in the output list is returned on success, an error
  494. * code reflecting the error condition is returned otherwise.
  495. */
  496. int acpi_dev_get_resources(struct acpi_device *adev, struct list_head *list,
  497. int (*preproc)(struct acpi_resource *, void *),
  498. void *preproc_data)
  499. {
  500. struct res_proc_context c;
  501. acpi_status status;
  502. if (!adev || !adev->handle || !list_empty(list))
  503. return -EINVAL;
  504. if (!acpi_has_method(adev->handle, METHOD_NAME__CRS))
  505. return 0;
  506. c.list = list;
  507. c.preproc = preproc;
  508. c.preproc_data = preproc_data;
  509. c.count = 0;
  510. c.error = 0;
  511. status = acpi_walk_resources(adev->handle, METHOD_NAME__CRS,
  512. acpi_dev_process_resource, &c);
  513. if (ACPI_FAILURE(status)) {
  514. acpi_dev_free_resource_list(list);
  515. return c.error ? c.error : -EIO;
  516. }
  517. return c.count;
  518. }
  519. EXPORT_SYMBOL_GPL(acpi_dev_get_resources);
  520. /**
  521. * acpi_dev_filter_resource_type - Filter ACPI resource according to resource
  522. * types
  523. * @ares: Input ACPI resource object.
  524. * @types: Valid resource types of IORESOURCE_XXX
  525. *
  526. * This is a helper function to support acpi_dev_get_resources(), which filters
  527. * ACPI resource objects according to resource types.
  528. */
  529. int acpi_dev_filter_resource_type(struct acpi_resource *ares,
  530. unsigned long types)
  531. {
  532. unsigned long type = 0;
  533. switch (ares->type) {
  534. case ACPI_RESOURCE_TYPE_MEMORY24:
  535. case ACPI_RESOURCE_TYPE_MEMORY32:
  536. case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
  537. type = IORESOURCE_MEM;
  538. break;
  539. case ACPI_RESOURCE_TYPE_IO:
  540. case ACPI_RESOURCE_TYPE_FIXED_IO:
  541. type = IORESOURCE_IO;
  542. break;
  543. case ACPI_RESOURCE_TYPE_IRQ:
  544. case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
  545. type = IORESOURCE_IRQ;
  546. break;
  547. case ACPI_RESOURCE_TYPE_DMA:
  548. case ACPI_RESOURCE_TYPE_FIXED_DMA:
  549. type = IORESOURCE_DMA;
  550. break;
  551. case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
  552. type = IORESOURCE_REG;
  553. break;
  554. case ACPI_RESOURCE_TYPE_ADDRESS16:
  555. case ACPI_RESOURCE_TYPE_ADDRESS32:
  556. case ACPI_RESOURCE_TYPE_ADDRESS64:
  557. case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
  558. if (ares->data.address.resource_type == ACPI_MEMORY_RANGE)
  559. type = IORESOURCE_MEM;
  560. else if (ares->data.address.resource_type == ACPI_IO_RANGE)
  561. type = IORESOURCE_IO;
  562. else if (ares->data.address.resource_type ==
  563. ACPI_BUS_NUMBER_RANGE)
  564. type = IORESOURCE_BUS;
  565. break;
  566. default:
  567. break;
  568. }
  569. return (type & types) ? 0 : 1;
  570. }
  571. EXPORT_SYMBOL_GPL(acpi_dev_filter_resource_type);