resource.c 19 KB

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