osl.c 34 KB

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