osl.c 34 KB

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