osl.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468
  1. /*
  2. * acpi_osl.c - OS-dependent functions ($Revision: 83 $)
  3. *
  4. * Copyright (C) 2000 Andrew Henroid
  5. * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
  6. * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
  7. * Copyright (c) 2008 Intel Corporation
  8. * Author: Matthew Wilcox <willy@linux.intel.com>
  9. *
  10. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25. *
  26. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  27. *
  28. */
  29. #include <linux/module.h>
  30. #include <linux/kernel.h>
  31. #include <linux/slab.h>
  32. #include <linux/mm.h>
  33. #include <linux/pci.h>
  34. #include <linux/interrupt.h>
  35. #include <linux/kmod.h>
  36. #include <linux/delay.h>
  37. #include <linux/workqueue.h>
  38. #include <linux/nmi.h>
  39. #include <linux/acpi.h>
  40. #include <linux/efi.h>
  41. #include <linux/ioport.h>
  42. #include <linux/list.h>
  43. #include <linux/jiffies.h>
  44. #include <linux/semaphore.h>
  45. #include <asm/io.h>
  46. #include <asm/uaccess.h>
  47. #include <acpi/acpi.h>
  48. #include <acpi/acpi_bus.h>
  49. #include <acpi/processor.h>
  50. #define _COMPONENT ACPI_OS_SERVICES
  51. ACPI_MODULE_NAME("osl");
  52. #define PREFIX "ACPI: "
  53. struct acpi_os_dpc {
  54. acpi_osd_exec_callback function;
  55. void *context;
  56. struct work_struct work;
  57. int wait;
  58. };
  59. #ifdef CONFIG_ACPI_CUSTOM_DSDT
  60. #include CONFIG_ACPI_CUSTOM_DSDT_FILE
  61. #endif
  62. #ifdef ENABLE_DEBUGGER
  63. #include <linux/kdb.h>
  64. /* stuff for debugger support */
  65. int acpi_in_debugger;
  66. EXPORT_SYMBOL(acpi_in_debugger);
  67. extern char line_buf[80];
  68. #endif /*ENABLE_DEBUGGER */
  69. static unsigned int acpi_irq_irq;
  70. static acpi_osd_handler acpi_irq_handler;
  71. static void *acpi_irq_context;
  72. static struct workqueue_struct *kacpid_wq;
  73. static struct workqueue_struct *kacpi_notify_wq;
  74. static struct workqueue_struct *kacpi_hotplug_wq;
  75. struct acpi_res_list {
  76. resource_size_t start;
  77. resource_size_t end;
  78. acpi_adr_space_type resource_type; /* IO port, System memory, ...*/
  79. char name[5]; /* only can have a length of 4 chars, make use of this
  80. one instead of res->name, no need to kalloc then */
  81. struct list_head resource_list;
  82. int count;
  83. };
  84. static LIST_HEAD(resource_list_head);
  85. static DEFINE_SPINLOCK(acpi_res_lock);
  86. #define OSI_STRING_LENGTH_MAX 64 /* arbitrary */
  87. static char osi_additional_string[OSI_STRING_LENGTH_MAX];
  88. /*
  89. * The story of _OSI(Linux)
  90. *
  91. * From pre-history through Linux-2.6.22,
  92. * Linux responded TRUE upon a BIOS OSI(Linux) query.
  93. *
  94. * Unfortunately, reference BIOS writers got wind of this
  95. * and put OSI(Linux) in their example code, quickly exposing
  96. * this string as ill-conceived and opening the door to
  97. * an un-bounded number of BIOS incompatibilities.
  98. *
  99. * For example, OSI(Linux) was used on resume to re-POST a
  100. * video card on one system, because Linux at that time
  101. * could not do a speedy restore in its native driver.
  102. * But then upon gaining quick native restore capability,
  103. * Linux has no way to tell the BIOS to skip the time-consuming
  104. * POST -- putting Linux at a permanent performance disadvantage.
  105. * On another system, the BIOS writer used OSI(Linux)
  106. * to infer native OS support for IPMI! On other systems,
  107. * OSI(Linux) simply got in the way of Linux claiming to
  108. * be compatible with other operating systems, exposing
  109. * BIOS issues such as skipped device initialization.
  110. *
  111. * So "Linux" turned out to be a really poor chose of
  112. * OSI string, and from Linux-2.6.23 onward we respond FALSE.
  113. *
  114. * BIOS writers should NOT query _OSI(Linux) on future systems.
  115. * Linux will complain on the console when it sees it, and return FALSE.
  116. * To get Linux to return TRUE for your system will require
  117. * a kernel source update to add a DMI entry,
  118. * or boot with "acpi_osi=Linux"
  119. */
  120. static struct osi_linux {
  121. unsigned int enable:1;
  122. unsigned int dmi:1;
  123. unsigned int cmdline:1;
  124. unsigned int known:1;
  125. } osi_linux = { 0, 0, 0, 0};
  126. static void __init acpi_request_region (struct acpi_generic_address *addr,
  127. unsigned int length, char *desc)
  128. {
  129. if (!addr->address || !length)
  130. return;
  131. /* Resources are never freed */
  132. if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_IO)
  133. request_region(addr->address, length, desc);
  134. else if (addr->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY)
  135. request_mem_region(addr->address, length, desc);
  136. }
  137. static int __init acpi_reserve_resources(void)
  138. {
  139. acpi_request_region(&acpi_gbl_FADT.xpm1a_event_block, acpi_gbl_FADT.pm1_event_length,
  140. "ACPI PM1a_EVT_BLK");
  141. acpi_request_region(&acpi_gbl_FADT.xpm1b_event_block, acpi_gbl_FADT.pm1_event_length,
  142. "ACPI PM1b_EVT_BLK");
  143. acpi_request_region(&acpi_gbl_FADT.xpm1a_control_block, acpi_gbl_FADT.pm1_control_length,
  144. "ACPI PM1a_CNT_BLK");
  145. acpi_request_region(&acpi_gbl_FADT.xpm1b_control_block, acpi_gbl_FADT.pm1_control_length,
  146. "ACPI PM1b_CNT_BLK");
  147. if (acpi_gbl_FADT.pm_timer_length == 4)
  148. acpi_request_region(&acpi_gbl_FADT.xpm_timer_block, 4, "ACPI PM_TMR");
  149. acpi_request_region(&acpi_gbl_FADT.xpm2_control_block, acpi_gbl_FADT.pm2_control_length,
  150. "ACPI PM2_CNT_BLK");
  151. /* Length of GPE blocks must be a non-negative multiple of 2 */
  152. if (!(acpi_gbl_FADT.gpe0_block_length & 0x1))
  153. acpi_request_region(&acpi_gbl_FADT.xgpe0_block,
  154. acpi_gbl_FADT.gpe0_block_length, "ACPI GPE0_BLK");
  155. if (!(acpi_gbl_FADT.gpe1_block_length & 0x1))
  156. acpi_request_region(&acpi_gbl_FADT.xgpe1_block,
  157. acpi_gbl_FADT.gpe1_block_length, "ACPI GPE1_BLK");
  158. return 0;
  159. }
  160. device_initcall(acpi_reserve_resources);
  161. acpi_status __init acpi_os_initialize(void)
  162. {
  163. return AE_OK;
  164. }
  165. acpi_status acpi_os_initialize1(void)
  166. {
  167. kacpid_wq = create_workqueue("kacpid");
  168. kacpi_notify_wq = create_workqueue("kacpi_notify");
  169. kacpi_hotplug_wq = create_workqueue("kacpi_hotplug");
  170. BUG_ON(!kacpid_wq);
  171. BUG_ON(!kacpi_notify_wq);
  172. BUG_ON(!kacpi_hotplug_wq);
  173. return AE_OK;
  174. }
  175. acpi_status acpi_os_terminate(void)
  176. {
  177. if (acpi_irq_handler) {
  178. acpi_os_remove_interrupt_handler(acpi_irq_irq,
  179. acpi_irq_handler);
  180. }
  181. destroy_workqueue(kacpid_wq);
  182. destroy_workqueue(kacpi_notify_wq);
  183. destroy_workqueue(kacpi_hotplug_wq);
  184. return AE_OK;
  185. }
  186. void acpi_os_printf(const char *fmt, ...)
  187. {
  188. va_list args;
  189. va_start(args, fmt);
  190. acpi_os_vprintf(fmt, args);
  191. va_end(args);
  192. }
  193. void acpi_os_vprintf(const char *fmt, va_list args)
  194. {
  195. static char buffer[512];
  196. vsprintf(buffer, fmt, args);
  197. #ifdef ENABLE_DEBUGGER
  198. if (acpi_in_debugger) {
  199. kdb_printf("%s", buffer);
  200. } else {
  201. printk(KERN_CONT "%s", buffer);
  202. }
  203. #else
  204. printk(KERN_CONT "%s", buffer);
  205. #endif
  206. }
  207. acpi_physical_address __init acpi_os_get_root_pointer(void)
  208. {
  209. if (efi_enabled) {
  210. if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
  211. return efi.acpi20;
  212. else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
  213. return efi.acpi;
  214. else {
  215. printk(KERN_ERR PREFIX
  216. "System description tables not found\n");
  217. return 0;
  218. }
  219. } else {
  220. acpi_physical_address pa = 0;
  221. acpi_find_root_pointer(&pa);
  222. return pa;
  223. }
  224. }
  225. void __iomem *__init_refok
  226. acpi_os_map_memory(acpi_physical_address phys, acpi_size size)
  227. {
  228. if (phys > ULONG_MAX) {
  229. printk(KERN_ERR PREFIX "Cannot map memory that high\n");
  230. return NULL;
  231. }
  232. if (acpi_gbl_permanent_mmap)
  233. /*
  234. * ioremap checks to ensure this is in reserved space
  235. */
  236. return ioremap((unsigned long)phys, size);
  237. else
  238. return __acpi_map_table((unsigned long)phys, size);
  239. }
  240. EXPORT_SYMBOL_GPL(acpi_os_map_memory);
  241. void __ref acpi_os_unmap_memory(void __iomem *virt, acpi_size size)
  242. {
  243. if (acpi_gbl_permanent_mmap)
  244. iounmap(virt);
  245. else
  246. __acpi_unmap_table(virt, size);
  247. }
  248. EXPORT_SYMBOL_GPL(acpi_os_unmap_memory);
  249. void __init early_acpi_os_unmap_memory(void __iomem *virt, acpi_size size)
  250. {
  251. if (!acpi_gbl_permanent_mmap)
  252. __acpi_unmap_table(virt, size);
  253. }
  254. #ifdef ACPI_FUTURE_USAGE
  255. acpi_status
  256. acpi_os_get_physical_address(void *virt, acpi_physical_address * phys)
  257. {
  258. if (!phys || !virt)
  259. return AE_BAD_PARAMETER;
  260. *phys = virt_to_phys(virt);
  261. return AE_OK;
  262. }
  263. #endif
  264. #define ACPI_MAX_OVERRIDE_LEN 100
  265. static char acpi_os_name[ACPI_MAX_OVERRIDE_LEN];
  266. acpi_status
  267. acpi_os_predefined_override(const struct acpi_predefined_names *init_val,
  268. acpi_string * new_val)
  269. {
  270. if (!init_val || !new_val)
  271. return AE_BAD_PARAMETER;
  272. *new_val = NULL;
  273. if (!memcmp(init_val->name, "_OS_", 4) && strlen(acpi_os_name)) {
  274. printk(KERN_INFO PREFIX "Overriding _OS definition to '%s'\n",
  275. acpi_os_name);
  276. *new_val = acpi_os_name;
  277. }
  278. return AE_OK;
  279. }
  280. acpi_status
  281. acpi_os_table_override(struct acpi_table_header * existing_table,
  282. struct acpi_table_header ** new_table)
  283. {
  284. if (!existing_table || !new_table)
  285. return AE_BAD_PARAMETER;
  286. *new_table = NULL;
  287. #ifdef CONFIG_ACPI_CUSTOM_DSDT
  288. if (strncmp(existing_table->signature, "DSDT", 4) == 0)
  289. *new_table = (struct acpi_table_header *)AmlCode;
  290. #endif
  291. if (*new_table != NULL) {
  292. printk(KERN_WARNING PREFIX "Override [%4.4s-%8.8s], "
  293. "this is unsafe: tainting kernel\n",
  294. existing_table->signature,
  295. existing_table->oem_table_id);
  296. add_taint(TAINT_OVERRIDDEN_ACPI_TABLE);
  297. }
  298. return AE_OK;
  299. }
  300. static irqreturn_t acpi_irq(int irq, void *dev_id)
  301. {
  302. u32 handled;
  303. handled = (*acpi_irq_handler) (acpi_irq_context);
  304. if (handled) {
  305. acpi_irq_handled++;
  306. return IRQ_HANDLED;
  307. } else {
  308. acpi_irq_not_handled++;
  309. return IRQ_NONE;
  310. }
  311. }
  312. acpi_status
  313. acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler,
  314. void *context)
  315. {
  316. unsigned int irq;
  317. acpi_irq_stats_init();
  318. /*
  319. * Ignore the GSI from the core, and use the value in our copy of the
  320. * FADT. It may not be the same if an interrupt source override exists
  321. * for the SCI.
  322. */
  323. gsi = acpi_gbl_FADT.sci_interrupt;
  324. if (acpi_gsi_to_irq(gsi, &irq) < 0) {
  325. printk(KERN_ERR PREFIX "SCI (ACPI GSI %d) not registered\n",
  326. gsi);
  327. return AE_OK;
  328. }
  329. acpi_irq_handler = handler;
  330. acpi_irq_context = context;
  331. if (request_irq(irq, acpi_irq, IRQF_SHARED, "acpi", acpi_irq)) {
  332. printk(KERN_ERR PREFIX "SCI (IRQ%d) allocation failed\n", irq);
  333. return AE_NOT_ACQUIRED;
  334. }
  335. acpi_irq_irq = irq;
  336. return AE_OK;
  337. }
  338. acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)
  339. {
  340. if (irq) {
  341. free_irq(irq, acpi_irq);
  342. acpi_irq_handler = NULL;
  343. acpi_irq_irq = 0;
  344. }
  345. return AE_OK;
  346. }
  347. /*
  348. * Running in interpreter thread context, safe to sleep
  349. */
  350. void acpi_os_sleep(u64 ms)
  351. {
  352. schedule_timeout_interruptible(msecs_to_jiffies(ms));
  353. }
  354. void acpi_os_stall(u32 us)
  355. {
  356. while (us) {
  357. u32 delay = 1000;
  358. if (delay > us)
  359. delay = us;
  360. udelay(delay);
  361. touch_nmi_watchdog();
  362. us -= delay;
  363. }
  364. }
  365. /*
  366. * Support ACPI 3.0 AML Timer operand
  367. * Returns 64-bit free-running, monotonically increasing timer
  368. * with 100ns granularity
  369. */
  370. u64 acpi_os_get_timer(void)
  371. {
  372. static u64 t;
  373. #ifdef CONFIG_HPET
  374. /* TBD: use HPET if available */
  375. #endif
  376. #ifdef CONFIG_X86_PM_TIMER
  377. /* TBD: default to PM timer if HPET was not available */
  378. #endif
  379. if (!t)
  380. printk(KERN_ERR PREFIX "acpi_os_get_timer() TBD\n");
  381. return ++t;
  382. }
  383. acpi_status acpi_os_read_port(acpi_io_address port, u32 * value, u32 width)
  384. {
  385. u32 dummy;
  386. if (!value)
  387. value = &dummy;
  388. *value = 0;
  389. if (width <= 8) {
  390. *(u8 *) value = inb(port);
  391. } else if (width <= 16) {
  392. *(u16 *) value = inw(port);
  393. } else if (width <= 32) {
  394. *(u32 *) value = inl(port);
  395. } else {
  396. BUG();
  397. }
  398. return AE_OK;
  399. }
  400. EXPORT_SYMBOL(acpi_os_read_port);
  401. acpi_status acpi_os_write_port(acpi_io_address port, u32 value, u32 width)
  402. {
  403. if (width <= 8) {
  404. outb(value, port);
  405. } else if (width <= 16) {
  406. outw(value, port);
  407. } else if (width <= 32) {
  408. outl(value, port);
  409. } else {
  410. BUG();
  411. }
  412. return AE_OK;
  413. }
  414. EXPORT_SYMBOL(acpi_os_write_port);
  415. acpi_status
  416. acpi_os_read_memory(acpi_physical_address phys_addr, u32 * value, u32 width)
  417. {
  418. u32 dummy;
  419. void __iomem *virt_addr;
  420. virt_addr = ioremap(phys_addr, width);
  421. if (!value)
  422. value = &dummy;
  423. switch (width) {
  424. case 8:
  425. *(u8 *) value = readb(virt_addr);
  426. break;
  427. case 16:
  428. *(u16 *) value = readw(virt_addr);
  429. break;
  430. case 32:
  431. *(u32 *) value = readl(virt_addr);
  432. break;
  433. default:
  434. BUG();
  435. }
  436. iounmap(virt_addr);
  437. return AE_OK;
  438. }
  439. acpi_status
  440. acpi_os_write_memory(acpi_physical_address phys_addr, u32 value, u32 width)
  441. {
  442. void __iomem *virt_addr;
  443. virt_addr = ioremap(phys_addr, width);
  444. switch (width) {
  445. case 8:
  446. writeb(value, virt_addr);
  447. break;
  448. case 16:
  449. writew(value, virt_addr);
  450. break;
  451. case 32:
  452. writel(value, virt_addr);
  453. break;
  454. default:
  455. BUG();
  456. }
  457. iounmap(virt_addr);
  458. return AE_OK;
  459. }
  460. acpi_status
  461. acpi_os_read_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
  462. u64 *value, u32 width)
  463. {
  464. int result, size;
  465. u32 value32;
  466. if (!value)
  467. return AE_BAD_PARAMETER;
  468. switch (width) {
  469. case 8:
  470. size = 1;
  471. break;
  472. case 16:
  473. size = 2;
  474. break;
  475. case 32:
  476. size = 4;
  477. break;
  478. default:
  479. return AE_ERROR;
  480. }
  481. result = raw_pci_read(pci_id->segment, pci_id->bus,
  482. PCI_DEVFN(pci_id->device, pci_id->function),
  483. reg, size, &value32);
  484. *value = value32;
  485. return (result ? AE_ERROR : AE_OK);
  486. }
  487. acpi_status
  488. acpi_os_write_pci_configuration(struct acpi_pci_id * pci_id, u32 reg,
  489. u64 value, u32 width)
  490. {
  491. int result, size;
  492. switch (width) {
  493. case 8:
  494. size = 1;
  495. break;
  496. case 16:
  497. size = 2;
  498. break;
  499. case 32:
  500. size = 4;
  501. break;
  502. default:
  503. return AE_ERROR;
  504. }
  505. result = raw_pci_write(pci_id->segment, pci_id->bus,
  506. PCI_DEVFN(pci_id->device, pci_id->function),
  507. reg, size, value);
  508. return (result ? AE_ERROR : AE_OK);
  509. }
  510. /* TODO: Change code to take advantage of driver model more */
  511. static void acpi_os_derive_pci_id_2(acpi_handle rhandle, /* upper bound */
  512. acpi_handle chandle, /* current node */
  513. struct acpi_pci_id **id,
  514. int *is_bridge, u8 * bus_number)
  515. {
  516. acpi_handle handle;
  517. struct acpi_pci_id *pci_id = *id;
  518. acpi_status status;
  519. unsigned long long temp;
  520. acpi_object_type type;
  521. acpi_get_parent(chandle, &handle);
  522. if (handle != rhandle) {
  523. acpi_os_derive_pci_id_2(rhandle, handle, &pci_id, is_bridge,
  524. bus_number);
  525. status = acpi_get_type(handle, &type);
  526. if ((ACPI_FAILURE(status)) || (type != ACPI_TYPE_DEVICE))
  527. return;
  528. status = acpi_evaluate_integer(handle, METHOD_NAME__ADR, NULL,
  529. &temp);
  530. if (ACPI_SUCCESS(status)) {
  531. u64 val;
  532. pci_id->device = ACPI_HIWORD(ACPI_LODWORD(temp));
  533. pci_id->function = ACPI_LOWORD(ACPI_LODWORD(temp));
  534. if (*is_bridge)
  535. pci_id->bus = *bus_number;
  536. /* any nicer way to get bus number of bridge ? */
  537. status =
  538. acpi_os_read_pci_configuration(pci_id, 0x0e, &val,
  539. 8);
  540. if (ACPI_SUCCESS(status)
  541. && ((val & 0x7f) == 1 || (val & 0x7f) == 2)) {
  542. status =
  543. acpi_os_read_pci_configuration(pci_id, 0x18,
  544. &val, 8);
  545. if (!ACPI_SUCCESS(status)) {
  546. /* Certainly broken... FIX ME */
  547. return;
  548. }
  549. *is_bridge = 1;
  550. pci_id->bus = val;
  551. status =
  552. acpi_os_read_pci_configuration(pci_id, 0x19,
  553. &val, 8);
  554. if (ACPI_SUCCESS(status)) {
  555. *bus_number = val;
  556. }
  557. } else
  558. *is_bridge = 0;
  559. }
  560. }
  561. }
  562. void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */
  563. acpi_handle chandle, /* current node */
  564. struct acpi_pci_id **id)
  565. {
  566. int is_bridge = 1;
  567. u8 bus_number = (*id)->bus;
  568. acpi_os_derive_pci_id_2(rhandle, chandle, id, &is_bridge, &bus_number);
  569. }
  570. static void acpi_os_execute_deferred(struct work_struct *work)
  571. {
  572. struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
  573. if (dpc->wait)
  574. acpi_os_wait_events_complete(NULL);
  575. dpc->function(dpc->context);
  576. kfree(dpc);
  577. }
  578. /*******************************************************************************
  579. *
  580. * FUNCTION: acpi_os_execute
  581. *
  582. * PARAMETERS: Type - Type of the callback
  583. * Function - Function to be executed
  584. * Context - Function parameters
  585. *
  586. * RETURN: Status
  587. *
  588. * DESCRIPTION: Depending on type, either queues function for deferred execution or
  589. * immediately executes function on a separate thread.
  590. *
  591. ******************************************************************************/
  592. static acpi_status __acpi_os_execute(acpi_execute_type type,
  593. acpi_osd_exec_callback function, void *context, int hp)
  594. {
  595. acpi_status status = AE_OK;
  596. struct acpi_os_dpc *dpc;
  597. struct workqueue_struct *queue;
  598. int ret;
  599. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  600. "Scheduling function [%p(%p)] for deferred execution.\n",
  601. function, context));
  602. /*
  603. * Allocate/initialize DPC structure. Note that this memory will be
  604. * freed by the callee. The kernel handles the work_struct list in a
  605. * way that allows us to also free its memory inside the callee.
  606. * Because we may want to schedule several tasks with different
  607. * parameters we can't use the approach some kernel code uses of
  608. * having a static work_struct.
  609. */
  610. dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC);
  611. if (!dpc)
  612. return AE_NO_MEMORY;
  613. dpc->function = function;
  614. dpc->context = context;
  615. /*
  616. * We can't run hotplug code in keventd_wq/kacpid_wq/kacpid_notify_wq
  617. * because the hotplug code may call driver .remove() functions,
  618. * which invoke flush_scheduled_work/acpi_os_wait_events_complete
  619. * to flush these workqueues.
  620. */
  621. queue = hp ? kacpi_hotplug_wq :
  622. (type == OSL_NOTIFY_HANDLER ? kacpi_notify_wq : kacpid_wq);
  623. dpc->wait = hp ? 1 : 0;
  624. if (queue == kacpi_hotplug_wq)
  625. INIT_WORK(&dpc->work, acpi_os_execute_deferred);
  626. else if (queue == kacpi_notify_wq)
  627. INIT_WORK(&dpc->work, acpi_os_execute_deferred);
  628. else
  629. INIT_WORK(&dpc->work, acpi_os_execute_deferred);
  630. /*
  631. * On some machines, a software-initiated SMI causes corruption unless
  632. * the SMI runs on CPU 0. An SMI can be initiated by any AML, but
  633. * typically it's done in GPE-related methods that are run via
  634. * workqueues, so we can avoid the known corruption cases by always
  635. * queueing on CPU 0.
  636. */
  637. ret = queue_work_on(0, queue, &dpc->work);
  638. if (!ret) {
  639. printk(KERN_ERR PREFIX
  640. "Call to queue_work() failed.\n");
  641. status = AE_ERROR;
  642. kfree(dpc);
  643. }
  644. return status;
  645. }
  646. acpi_status acpi_os_execute(acpi_execute_type type,
  647. acpi_osd_exec_callback function, void *context)
  648. {
  649. return __acpi_os_execute(type, function, context, 0);
  650. }
  651. EXPORT_SYMBOL(acpi_os_execute);
  652. acpi_status acpi_os_hotplug_execute(acpi_osd_exec_callback function,
  653. void *context)
  654. {
  655. return __acpi_os_execute(0, function, context, 1);
  656. }
  657. void acpi_os_wait_events_complete(void *context)
  658. {
  659. flush_workqueue(kacpid_wq);
  660. flush_workqueue(kacpi_notify_wq);
  661. }
  662. EXPORT_SYMBOL(acpi_os_wait_events_complete);
  663. /*
  664. * Allocate the memory for a spinlock and initialize it.
  665. */
  666. acpi_status acpi_os_create_lock(acpi_spinlock * handle)
  667. {
  668. spin_lock_init(*handle);
  669. return AE_OK;
  670. }
  671. /*
  672. * Deallocate the memory for a spinlock.
  673. */
  674. void acpi_os_delete_lock(acpi_spinlock handle)
  675. {
  676. return;
  677. }
  678. acpi_status
  679. acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
  680. {
  681. struct semaphore *sem = NULL;
  682. sem = acpi_os_allocate(sizeof(struct semaphore));
  683. if (!sem)
  684. return AE_NO_MEMORY;
  685. memset(sem, 0, sizeof(struct semaphore));
  686. sema_init(sem, initial_units);
  687. *handle = (acpi_handle *) sem;
  688. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
  689. *handle, initial_units));
  690. return AE_OK;
  691. }
  692. /*
  693. * TODO: A better way to delete semaphores? Linux doesn't have a
  694. * 'delete_semaphore()' function -- may result in an invalid
  695. * pointer dereference for non-synchronized consumers. Should
  696. * we at least check for blocked threads and signal/cancel them?
  697. */
  698. acpi_status acpi_os_delete_semaphore(acpi_handle handle)
  699. {
  700. struct semaphore *sem = (struct semaphore *)handle;
  701. if (!sem)
  702. return AE_BAD_PARAMETER;
  703. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
  704. BUG_ON(!list_empty(&sem->wait_list));
  705. kfree(sem);
  706. sem = NULL;
  707. return AE_OK;
  708. }
  709. /*
  710. * TODO: Support for units > 1?
  711. */
  712. acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
  713. {
  714. acpi_status status = AE_OK;
  715. struct semaphore *sem = (struct semaphore *)handle;
  716. long jiffies;
  717. int ret = 0;
  718. if (!sem || (units < 1))
  719. return AE_BAD_PARAMETER;
  720. if (units > 1)
  721. return AE_SUPPORT;
  722. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
  723. handle, units, timeout));
  724. if (timeout == ACPI_WAIT_FOREVER)
  725. jiffies = MAX_SCHEDULE_TIMEOUT;
  726. else
  727. jiffies = msecs_to_jiffies(timeout);
  728. ret = down_timeout(sem, jiffies);
  729. if (ret)
  730. status = AE_TIME;
  731. if (ACPI_FAILURE(status)) {
  732. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
  733. "Failed to acquire semaphore[%p|%d|%d], %s",
  734. handle, units, timeout,
  735. acpi_format_exception(status)));
  736. } else {
  737. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
  738. "Acquired semaphore[%p|%d|%d]", handle,
  739. units, timeout));
  740. }
  741. return status;
  742. }
  743. /*
  744. * TODO: Support for units > 1?
  745. */
  746. acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
  747. {
  748. struct semaphore *sem = (struct semaphore *)handle;
  749. if (!sem || (units < 1))
  750. return AE_BAD_PARAMETER;
  751. if (units > 1)
  752. return AE_SUPPORT;
  753. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
  754. units));
  755. up(sem);
  756. return AE_OK;
  757. }
  758. #ifdef ACPI_FUTURE_USAGE
  759. u32 acpi_os_get_line(char *buffer)
  760. {
  761. #ifdef ENABLE_DEBUGGER
  762. if (acpi_in_debugger) {
  763. u32 chars;
  764. kdb_read(buffer, sizeof(line_buf));
  765. /* remove the CR kdb includes */
  766. chars = strlen(buffer) - 1;
  767. buffer[chars] = '\0';
  768. }
  769. #endif
  770. return 0;
  771. }
  772. #endif /* ACPI_FUTURE_USAGE */
  773. acpi_status acpi_os_signal(u32 function, void *info)
  774. {
  775. switch (function) {
  776. case ACPI_SIGNAL_FATAL:
  777. printk(KERN_ERR PREFIX "Fatal opcode executed\n");
  778. break;
  779. case ACPI_SIGNAL_BREAKPOINT:
  780. /*
  781. * AML Breakpoint
  782. * ACPI spec. says to treat it as a NOP unless
  783. * you are debugging. So if/when we integrate
  784. * AML debugger into the kernel debugger its
  785. * hook will go here. But until then it is
  786. * not useful to print anything on breakpoints.
  787. */
  788. break;
  789. default:
  790. break;
  791. }
  792. return AE_OK;
  793. }
  794. static int __init acpi_os_name_setup(char *str)
  795. {
  796. char *p = acpi_os_name;
  797. int count = ACPI_MAX_OVERRIDE_LEN - 1;
  798. if (!str || !*str)
  799. return 0;
  800. for (; count-- && str && *str; str++) {
  801. if (isalnum(*str) || *str == ' ' || *str == ':')
  802. *p++ = *str;
  803. else if (*str == '\'' || *str == '"')
  804. continue;
  805. else
  806. break;
  807. }
  808. *p = 0;
  809. return 1;
  810. }
  811. __setup("acpi_os_name=", acpi_os_name_setup);
  812. static void __init set_osi_linux(unsigned int enable)
  813. {
  814. if (osi_linux.enable != enable) {
  815. osi_linux.enable = enable;
  816. printk(KERN_NOTICE PREFIX "%sed _OSI(Linux)\n",
  817. enable ? "Add": "Delet");
  818. }
  819. return;
  820. }
  821. static void __init acpi_cmdline_osi_linux(unsigned int enable)
  822. {
  823. osi_linux.cmdline = 1; /* cmdline set the default */
  824. set_osi_linux(enable);
  825. return;
  826. }
  827. void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d)
  828. {
  829. osi_linux.dmi = 1; /* DMI knows that this box asks OSI(Linux) */
  830. printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident);
  831. if (enable == -1)
  832. return;
  833. osi_linux.known = 1; /* DMI knows which OSI(Linux) default needed */
  834. set_osi_linux(enable);
  835. return;
  836. }
  837. /*
  838. * Modify the list of "OS Interfaces" reported to BIOS via _OSI
  839. *
  840. * empty string disables _OSI
  841. * string starting with '!' disables that string
  842. * otherwise string is added to list, augmenting built-in strings
  843. */
  844. int __init acpi_osi_setup(char *str)
  845. {
  846. if (str == NULL || *str == '\0') {
  847. printk(KERN_INFO PREFIX "_OSI method disabled\n");
  848. acpi_gbl_create_osi_method = FALSE;
  849. } else if (!strcmp("!Linux", str)) {
  850. acpi_cmdline_osi_linux(0); /* !enable */
  851. } else if (*str == '!') {
  852. if (acpi_osi_invalidate(++str) == AE_OK)
  853. printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str);
  854. } else if (!strcmp("Linux", str)) {
  855. acpi_cmdline_osi_linux(1); /* enable */
  856. } else if (*osi_additional_string == '\0') {
  857. strncpy(osi_additional_string, str, OSI_STRING_LENGTH_MAX);
  858. printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str);
  859. }
  860. return 1;
  861. }
  862. __setup("acpi_osi=", acpi_osi_setup);
  863. /* enable serialization to combat AE_ALREADY_EXISTS errors */
  864. static int __init acpi_serialize_setup(char *str)
  865. {
  866. printk(KERN_INFO PREFIX "serialize enabled\n");
  867. acpi_gbl_all_methods_serialized = TRUE;
  868. return 1;
  869. }
  870. __setup("acpi_serialize", acpi_serialize_setup);
  871. /* Check of resource interference between native drivers and ACPI
  872. * OperationRegions (SystemIO and System Memory only).
  873. * IO ports and memory declared in ACPI might be used by the ACPI subsystem
  874. * in arbitrary AML code and can interfere with legacy drivers.
  875. * acpi_enforce_resources= can be set to:
  876. *
  877. * - strict (default) (2)
  878. * -> further driver trying to access the resources will not load
  879. * - lax (1)
  880. * -> further driver trying to access the resources will load, but you
  881. * get a system message that something might go wrong...
  882. *
  883. * - no (0)
  884. * -> ACPI Operation Region resources will not be registered
  885. *
  886. */
  887. #define ENFORCE_RESOURCES_STRICT 2
  888. #define ENFORCE_RESOURCES_LAX 1
  889. #define ENFORCE_RESOURCES_NO 0
  890. static unsigned int acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
  891. static int __init acpi_enforce_resources_setup(char *str)
  892. {
  893. if (str == NULL || *str == '\0')
  894. return 0;
  895. if (!strcmp("strict", str))
  896. acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
  897. else if (!strcmp("lax", str))
  898. acpi_enforce_resources = ENFORCE_RESOURCES_LAX;
  899. else if (!strcmp("no", str))
  900. acpi_enforce_resources = ENFORCE_RESOURCES_NO;
  901. return 1;
  902. }
  903. __setup("acpi_enforce_resources=", acpi_enforce_resources_setup);
  904. /* Check for resource conflicts between ACPI OperationRegions and native
  905. * drivers */
  906. int acpi_check_resource_conflict(const struct resource *res)
  907. {
  908. struct acpi_res_list *res_list_elem;
  909. int ioport;
  910. int clash = 0;
  911. if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
  912. return 0;
  913. if (!(res->flags & IORESOURCE_IO) && !(res->flags & IORESOURCE_MEM))
  914. return 0;
  915. ioport = res->flags & IORESOURCE_IO;
  916. spin_lock(&acpi_res_lock);
  917. list_for_each_entry(res_list_elem, &resource_list_head,
  918. resource_list) {
  919. if (ioport && (res_list_elem->resource_type
  920. != ACPI_ADR_SPACE_SYSTEM_IO))
  921. continue;
  922. if (!ioport && (res_list_elem->resource_type
  923. != ACPI_ADR_SPACE_SYSTEM_MEMORY))
  924. continue;
  925. if (res->end < res_list_elem->start
  926. || res_list_elem->end < res->start)
  927. continue;
  928. clash = 1;
  929. break;
  930. }
  931. spin_unlock(&acpi_res_lock);
  932. if (clash) {
  933. if (acpi_enforce_resources != ENFORCE_RESOURCES_NO) {
  934. printk(KERN_WARNING "ACPI: resource %s %pR"
  935. " conflicts with ACPI region %s %pR\n",
  936. res->name, res, res_list_elem->name,
  937. res_list_elem);
  938. if (acpi_enforce_resources == ENFORCE_RESOURCES_LAX)
  939. printk(KERN_NOTICE "ACPI: This conflict may"
  940. " cause random problems and system"
  941. " instability\n");
  942. printk(KERN_INFO "ACPI: If an ACPI driver is available"
  943. " for this device, you should use it instead of"
  944. " the native driver\n");
  945. }
  946. if (acpi_enforce_resources == ENFORCE_RESOURCES_STRICT)
  947. return -EBUSY;
  948. }
  949. return 0;
  950. }
  951. EXPORT_SYMBOL(acpi_check_resource_conflict);
  952. int acpi_check_region(resource_size_t start, resource_size_t n,
  953. const char *name)
  954. {
  955. struct resource res = {
  956. .start = start,
  957. .end = start + n - 1,
  958. .name = name,
  959. .flags = IORESOURCE_IO,
  960. };
  961. return acpi_check_resource_conflict(&res);
  962. }
  963. EXPORT_SYMBOL(acpi_check_region);
  964. int acpi_check_mem_region(resource_size_t start, resource_size_t n,
  965. const char *name)
  966. {
  967. struct resource res = {
  968. .start = start,
  969. .end = start + n - 1,
  970. .name = name,
  971. .flags = IORESOURCE_MEM,
  972. };
  973. return acpi_check_resource_conflict(&res);
  974. }
  975. EXPORT_SYMBOL(acpi_check_mem_region);
  976. /*
  977. * Let drivers know whether the resource checks are effective
  978. */
  979. int acpi_resources_are_enforced(void)
  980. {
  981. return acpi_enforce_resources == ENFORCE_RESOURCES_STRICT;
  982. }
  983. EXPORT_SYMBOL(acpi_resources_are_enforced);
  984. /*
  985. * Acquire a spinlock.
  986. *
  987. * handle is a pointer to the spinlock_t.
  988. */
  989. acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
  990. {
  991. acpi_cpu_flags flags;
  992. spin_lock_irqsave(lockp, flags);
  993. return flags;
  994. }
  995. /*
  996. * Release a spinlock. See above.
  997. */
  998. void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
  999. {
  1000. spin_unlock_irqrestore(lockp, flags);
  1001. }
  1002. #ifndef ACPI_USE_LOCAL_CACHE
  1003. /*******************************************************************************
  1004. *
  1005. * FUNCTION: acpi_os_create_cache
  1006. *
  1007. * PARAMETERS: name - Ascii name for the cache
  1008. * size - Size of each cached object
  1009. * depth - Maximum depth of the cache (in objects) <ignored>
  1010. * cache - Where the new cache object is returned
  1011. *
  1012. * RETURN: status
  1013. *
  1014. * DESCRIPTION: Create a cache object
  1015. *
  1016. ******************************************************************************/
  1017. acpi_status
  1018. acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
  1019. {
  1020. *cache = kmem_cache_create(name, size, 0, 0, NULL);
  1021. if (*cache == NULL)
  1022. return AE_ERROR;
  1023. else
  1024. return AE_OK;
  1025. }
  1026. /*******************************************************************************
  1027. *
  1028. * FUNCTION: acpi_os_purge_cache
  1029. *
  1030. * PARAMETERS: Cache - Handle to cache object
  1031. *
  1032. * RETURN: Status
  1033. *
  1034. * DESCRIPTION: Free all objects within the requested cache.
  1035. *
  1036. ******************************************************************************/
  1037. acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
  1038. {
  1039. kmem_cache_shrink(cache);
  1040. return (AE_OK);
  1041. }
  1042. /*******************************************************************************
  1043. *
  1044. * FUNCTION: acpi_os_delete_cache
  1045. *
  1046. * PARAMETERS: Cache - Handle to cache object
  1047. *
  1048. * RETURN: Status
  1049. *
  1050. * DESCRIPTION: Free all objects within the requested cache and delete the
  1051. * cache object.
  1052. *
  1053. ******************************************************************************/
  1054. acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
  1055. {
  1056. kmem_cache_destroy(cache);
  1057. return (AE_OK);
  1058. }
  1059. /*******************************************************************************
  1060. *
  1061. * FUNCTION: acpi_os_release_object
  1062. *
  1063. * PARAMETERS: Cache - Handle to cache object
  1064. * Object - The object to be released
  1065. *
  1066. * RETURN: None
  1067. *
  1068. * DESCRIPTION: Release an object to the specified cache. If cache is full,
  1069. * the object is deleted.
  1070. *
  1071. ******************************************************************************/
  1072. acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
  1073. {
  1074. kmem_cache_free(cache, object);
  1075. return (AE_OK);
  1076. }
  1077. /******************************************************************************
  1078. *
  1079. * FUNCTION: acpi_os_validate_interface
  1080. *
  1081. * PARAMETERS: interface - Requested interface to be validated
  1082. *
  1083. * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
  1084. *
  1085. * DESCRIPTION: Match an interface string to the interfaces supported by the
  1086. * host. Strings originate from an AML call to the _OSI method.
  1087. *
  1088. *****************************************************************************/
  1089. acpi_status
  1090. acpi_os_validate_interface (char *interface)
  1091. {
  1092. if (!strncmp(osi_additional_string, interface, OSI_STRING_LENGTH_MAX))
  1093. return AE_OK;
  1094. if (!strcmp("Linux", interface)) {
  1095. printk(KERN_NOTICE PREFIX
  1096. "BIOS _OSI(Linux) query %s%s\n",
  1097. osi_linux.enable ? "honored" : "ignored",
  1098. osi_linux.cmdline ? " via cmdline" :
  1099. osi_linux.dmi ? " via DMI" : "");
  1100. if (osi_linux.enable)
  1101. return AE_OK;
  1102. }
  1103. return AE_SUPPORT;
  1104. }
  1105. static inline int acpi_res_list_add(struct acpi_res_list *res)
  1106. {
  1107. struct acpi_res_list *res_list_elem;
  1108. list_for_each_entry(res_list_elem, &resource_list_head,
  1109. resource_list) {
  1110. if (res->resource_type == res_list_elem->resource_type &&
  1111. res->start == res_list_elem->start &&
  1112. res->end == res_list_elem->end) {
  1113. /*
  1114. * The Region(addr,len) already exist in the list,
  1115. * just increase the count
  1116. */
  1117. res_list_elem->count++;
  1118. return 0;
  1119. }
  1120. }
  1121. res->count = 1;
  1122. list_add(&res->resource_list, &resource_list_head);
  1123. return 1;
  1124. }
  1125. static inline void acpi_res_list_del(struct acpi_res_list *res)
  1126. {
  1127. struct acpi_res_list *res_list_elem;
  1128. list_for_each_entry(res_list_elem, &resource_list_head,
  1129. resource_list) {
  1130. if (res->resource_type == res_list_elem->resource_type &&
  1131. res->start == res_list_elem->start &&
  1132. res->end == res_list_elem->end) {
  1133. /*
  1134. * If the res count is decreased to 0,
  1135. * remove and free it
  1136. */
  1137. if (--res_list_elem->count == 0) {
  1138. list_del(&res_list_elem->resource_list);
  1139. kfree(res_list_elem);
  1140. }
  1141. return;
  1142. }
  1143. }
  1144. }
  1145. acpi_status
  1146. acpi_os_invalidate_address(
  1147. u8 space_id,
  1148. acpi_physical_address address,
  1149. acpi_size length)
  1150. {
  1151. struct acpi_res_list res;
  1152. switch (space_id) {
  1153. case ACPI_ADR_SPACE_SYSTEM_IO:
  1154. case ACPI_ADR_SPACE_SYSTEM_MEMORY:
  1155. /* Only interference checks against SystemIO and SystemMemory
  1156. are needed */
  1157. res.start = address;
  1158. res.end = address + length - 1;
  1159. res.resource_type = space_id;
  1160. spin_lock(&acpi_res_lock);
  1161. acpi_res_list_del(&res);
  1162. spin_unlock(&acpi_res_lock);
  1163. break;
  1164. case ACPI_ADR_SPACE_PCI_CONFIG:
  1165. case ACPI_ADR_SPACE_EC:
  1166. case ACPI_ADR_SPACE_SMBUS:
  1167. case ACPI_ADR_SPACE_CMOS:
  1168. case ACPI_ADR_SPACE_PCI_BAR_TARGET:
  1169. case ACPI_ADR_SPACE_DATA_TABLE:
  1170. case ACPI_ADR_SPACE_FIXED_HARDWARE:
  1171. break;
  1172. }
  1173. return AE_OK;
  1174. }
  1175. /******************************************************************************
  1176. *
  1177. * FUNCTION: acpi_os_validate_address
  1178. *
  1179. * PARAMETERS: space_id - ACPI space ID
  1180. * address - Physical address
  1181. * length - Address length
  1182. *
  1183. * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
  1184. * should return AE_AML_ILLEGAL_ADDRESS.
  1185. *
  1186. * DESCRIPTION: Validate a system address via the host OS. Used to validate
  1187. * the addresses accessed by AML operation regions.
  1188. *
  1189. *****************************************************************************/
  1190. acpi_status
  1191. acpi_os_validate_address (
  1192. u8 space_id,
  1193. acpi_physical_address address,
  1194. acpi_size length,
  1195. char *name)
  1196. {
  1197. struct acpi_res_list *res;
  1198. int added;
  1199. if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
  1200. return AE_OK;
  1201. switch (space_id) {
  1202. case ACPI_ADR_SPACE_SYSTEM_IO:
  1203. case ACPI_ADR_SPACE_SYSTEM_MEMORY:
  1204. /* Only interference checks against SystemIO and SystemMemory
  1205. are needed */
  1206. res = kzalloc(sizeof(struct acpi_res_list), GFP_KERNEL);
  1207. if (!res)
  1208. return AE_OK;
  1209. /* ACPI names are fixed to 4 bytes, still better use strlcpy */
  1210. strlcpy(res->name, name, 5);
  1211. res->start = address;
  1212. res->end = address + length - 1;
  1213. res->resource_type = space_id;
  1214. spin_lock(&acpi_res_lock);
  1215. added = acpi_res_list_add(res);
  1216. spin_unlock(&acpi_res_lock);
  1217. pr_debug("%s %s resource: start: 0x%llx, end: 0x%llx, "
  1218. "name: %s\n", added ? "Added" : "Already exist",
  1219. (space_id == ACPI_ADR_SPACE_SYSTEM_IO)
  1220. ? "SystemIO" : "System Memory",
  1221. (unsigned long long)res->start,
  1222. (unsigned long long)res->end,
  1223. res->name);
  1224. if (!added)
  1225. kfree(res);
  1226. break;
  1227. case ACPI_ADR_SPACE_PCI_CONFIG:
  1228. case ACPI_ADR_SPACE_EC:
  1229. case ACPI_ADR_SPACE_SMBUS:
  1230. case ACPI_ADR_SPACE_CMOS:
  1231. case ACPI_ADR_SPACE_PCI_BAR_TARGET:
  1232. case ACPI_ADR_SPACE_DATA_TABLE:
  1233. case ACPI_ADR_SPACE_FIXED_HARDWARE:
  1234. break;
  1235. }
  1236. return AE_OK;
  1237. }
  1238. #endif