osl.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401
  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. flush_workqueue(kacpi_notify_wq);
  630. }
  631. EXPORT_SYMBOL(acpi_os_wait_events_complete);
  632. /*
  633. * Allocate the memory for a spinlock and initialize it.
  634. */
  635. acpi_status acpi_os_create_lock(acpi_spinlock * handle)
  636. {
  637. spin_lock_init(*handle);
  638. return AE_OK;
  639. }
  640. /*
  641. * Deallocate the memory for a spinlock.
  642. */
  643. void acpi_os_delete_lock(acpi_spinlock handle)
  644. {
  645. return;
  646. }
  647. acpi_status
  648. acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
  649. {
  650. struct semaphore *sem = NULL;
  651. sem = acpi_os_allocate(sizeof(struct semaphore));
  652. if (!sem)
  653. return AE_NO_MEMORY;
  654. memset(sem, 0, sizeof(struct semaphore));
  655. sema_init(sem, initial_units);
  656. *handle = (acpi_handle *) sem;
  657. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
  658. *handle, initial_units));
  659. return AE_OK;
  660. }
  661. /*
  662. * TODO: A better way to delete semaphores? Linux doesn't have a
  663. * 'delete_semaphore()' function -- may result in an invalid
  664. * pointer dereference for non-synchronized consumers. Should
  665. * we at least check for blocked threads and signal/cancel them?
  666. */
  667. acpi_status acpi_os_delete_semaphore(acpi_handle handle)
  668. {
  669. struct semaphore *sem = (struct semaphore *)handle;
  670. if (!sem)
  671. return AE_BAD_PARAMETER;
  672. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
  673. BUG_ON(!list_empty(&sem->wait_list));
  674. kfree(sem);
  675. sem = NULL;
  676. return AE_OK;
  677. }
  678. /*
  679. * TODO: Support for units > 1?
  680. */
  681. acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
  682. {
  683. acpi_status status = AE_OK;
  684. struct semaphore *sem = (struct semaphore *)handle;
  685. long jiffies;
  686. int ret = 0;
  687. if (!sem || (units < 1))
  688. return AE_BAD_PARAMETER;
  689. if (units > 1)
  690. return AE_SUPPORT;
  691. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
  692. handle, units, timeout));
  693. if (timeout == ACPI_WAIT_FOREVER)
  694. jiffies = MAX_SCHEDULE_TIMEOUT;
  695. else
  696. jiffies = msecs_to_jiffies(timeout);
  697. ret = down_timeout(sem, jiffies);
  698. if (ret)
  699. status = AE_TIME;
  700. if (ACPI_FAILURE(status)) {
  701. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
  702. "Failed to acquire semaphore[%p|%d|%d], %s",
  703. handle, units, timeout,
  704. acpi_format_exception(status)));
  705. } else {
  706. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
  707. "Acquired semaphore[%p|%d|%d]", handle,
  708. units, timeout));
  709. }
  710. return status;
  711. }
  712. /*
  713. * TODO: Support for units > 1?
  714. */
  715. acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
  716. {
  717. struct semaphore *sem = (struct semaphore *)handle;
  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, "Signaling semaphore[%p|%d]\n", handle,
  723. units));
  724. up(sem);
  725. return AE_OK;
  726. }
  727. #ifdef ACPI_FUTURE_USAGE
  728. u32 acpi_os_get_line(char *buffer)
  729. {
  730. #ifdef ENABLE_DEBUGGER
  731. if (acpi_in_debugger) {
  732. u32 chars;
  733. kdb_read(buffer, sizeof(line_buf));
  734. /* remove the CR kdb includes */
  735. chars = strlen(buffer) - 1;
  736. buffer[chars] = '\0';
  737. }
  738. #endif
  739. return 0;
  740. }
  741. #endif /* ACPI_FUTURE_USAGE */
  742. acpi_status acpi_os_signal(u32 function, void *info)
  743. {
  744. switch (function) {
  745. case ACPI_SIGNAL_FATAL:
  746. printk(KERN_ERR PREFIX "Fatal opcode executed\n");
  747. break;
  748. case ACPI_SIGNAL_BREAKPOINT:
  749. /*
  750. * AML Breakpoint
  751. * ACPI spec. says to treat it as a NOP unless
  752. * you are debugging. So if/when we integrate
  753. * AML debugger into the kernel debugger its
  754. * hook will go here. But until then it is
  755. * not useful to print anything on breakpoints.
  756. */
  757. break;
  758. default:
  759. break;
  760. }
  761. return AE_OK;
  762. }
  763. static int __init acpi_os_name_setup(char *str)
  764. {
  765. char *p = acpi_os_name;
  766. int count = ACPI_MAX_OVERRIDE_LEN - 1;
  767. if (!str || !*str)
  768. return 0;
  769. for (; count-- && str && *str; str++) {
  770. if (isalnum(*str) || *str == ' ' || *str == ':')
  771. *p++ = *str;
  772. else if (*str == '\'' || *str == '"')
  773. continue;
  774. else
  775. break;
  776. }
  777. *p = 0;
  778. return 1;
  779. }
  780. __setup("acpi_os_name=", acpi_os_name_setup);
  781. static void __init set_osi_linux(unsigned int enable)
  782. {
  783. if (osi_linux.enable != enable) {
  784. osi_linux.enable = enable;
  785. printk(KERN_NOTICE PREFIX "%sed _OSI(Linux)\n",
  786. enable ? "Add": "Delet");
  787. }
  788. return;
  789. }
  790. static void __init acpi_cmdline_osi_linux(unsigned int enable)
  791. {
  792. osi_linux.cmdline = 1; /* cmdline set the default */
  793. set_osi_linux(enable);
  794. return;
  795. }
  796. void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d)
  797. {
  798. osi_linux.dmi = 1; /* DMI knows that this box asks OSI(Linux) */
  799. printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident);
  800. if (enable == -1)
  801. return;
  802. osi_linux.known = 1; /* DMI knows which OSI(Linux) default needed */
  803. set_osi_linux(enable);
  804. return;
  805. }
  806. /*
  807. * Modify the list of "OS Interfaces" reported to BIOS via _OSI
  808. *
  809. * empty string disables _OSI
  810. * string starting with '!' disables that string
  811. * otherwise string is added to list, augmenting built-in strings
  812. */
  813. int __init acpi_osi_setup(char *str)
  814. {
  815. if (str == NULL || *str == '\0') {
  816. printk(KERN_INFO PREFIX "_OSI method disabled\n");
  817. acpi_gbl_create_osi_method = FALSE;
  818. } else if (!strcmp("!Linux", str)) {
  819. acpi_cmdline_osi_linux(0); /* !enable */
  820. } else if (*str == '!') {
  821. if (acpi_osi_invalidate(++str) == AE_OK)
  822. printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str);
  823. } else if (!strcmp("Linux", str)) {
  824. acpi_cmdline_osi_linux(1); /* enable */
  825. } else if (*osi_additional_string == '\0') {
  826. strncpy(osi_additional_string, str, OSI_STRING_LENGTH_MAX);
  827. printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str);
  828. }
  829. return 1;
  830. }
  831. __setup("acpi_osi=", acpi_osi_setup);
  832. /* enable serialization to combat AE_ALREADY_EXISTS errors */
  833. static int __init acpi_serialize_setup(char *str)
  834. {
  835. printk(KERN_INFO PREFIX "serialize enabled\n");
  836. acpi_gbl_all_methods_serialized = TRUE;
  837. return 1;
  838. }
  839. __setup("acpi_serialize", acpi_serialize_setup);
  840. /*
  841. * Wake and Run-Time GPES are expected to be separate.
  842. * We disable wake-GPEs at run-time to prevent spurious
  843. * interrupts.
  844. *
  845. * However, if a system exists that shares Wake and
  846. * Run-time events on the same GPE this flag is available
  847. * to tell Linux to keep the wake-time GPEs enabled at run-time.
  848. */
  849. static int __init acpi_wake_gpes_always_on_setup(char *str)
  850. {
  851. printk(KERN_INFO PREFIX "wake GPEs not disabled\n");
  852. acpi_gbl_leave_wake_gpes_disabled = FALSE;
  853. return 1;
  854. }
  855. __setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
  856. /* Check of resource interference between native drivers and ACPI
  857. * OperationRegions (SystemIO and System Memory only).
  858. * IO ports and memory declared in ACPI might be used by the ACPI subsystem
  859. * in arbitrary AML code and can interfere with legacy drivers.
  860. * acpi_enforce_resources= can be set to:
  861. *
  862. * - strict (2)
  863. * -> further driver trying to access the resources will not load
  864. * - lax (default) (1)
  865. * -> further driver trying to access the resources will load, but you
  866. * get a system message that something might go wrong...
  867. *
  868. * - no (0)
  869. * -> ACPI Operation Region resources will not be registered
  870. *
  871. */
  872. #define ENFORCE_RESOURCES_STRICT 2
  873. #define ENFORCE_RESOURCES_LAX 1
  874. #define ENFORCE_RESOURCES_NO 0
  875. static unsigned int acpi_enforce_resources = ENFORCE_RESOURCES_LAX;
  876. static int __init acpi_enforce_resources_setup(char *str)
  877. {
  878. if (str == NULL || *str == '\0')
  879. return 0;
  880. if (!strcmp("strict", str))
  881. acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
  882. else if (!strcmp("lax", str))
  883. acpi_enforce_resources = ENFORCE_RESOURCES_LAX;
  884. else if (!strcmp("no", str))
  885. acpi_enforce_resources = ENFORCE_RESOURCES_NO;
  886. return 1;
  887. }
  888. __setup("acpi_enforce_resources=", acpi_enforce_resources_setup);
  889. /* Check for resource conflicts between ACPI OperationRegions and native
  890. * drivers */
  891. int acpi_check_resource_conflict(struct resource *res)
  892. {
  893. struct acpi_res_list *res_list_elem;
  894. int ioport;
  895. int clash = 0;
  896. if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
  897. return 0;
  898. if (!(res->flags & IORESOURCE_IO) && !(res->flags & IORESOURCE_MEM))
  899. return 0;
  900. ioport = res->flags & IORESOURCE_IO;
  901. spin_lock(&acpi_res_lock);
  902. list_for_each_entry(res_list_elem, &resource_list_head,
  903. resource_list) {
  904. if (ioport && (res_list_elem->resource_type
  905. != ACPI_ADR_SPACE_SYSTEM_IO))
  906. continue;
  907. if (!ioport && (res_list_elem->resource_type
  908. != ACPI_ADR_SPACE_SYSTEM_MEMORY))
  909. continue;
  910. if (res->end < res_list_elem->start
  911. || res_list_elem->end < res->start)
  912. continue;
  913. clash = 1;
  914. break;
  915. }
  916. spin_unlock(&acpi_res_lock);
  917. if (clash) {
  918. if (acpi_enforce_resources != ENFORCE_RESOURCES_NO) {
  919. printk("%sACPI: %s resource %s [0x%llx-0x%llx]"
  920. " conflicts with ACPI region %s"
  921. " [0x%llx-0x%llx]\n",
  922. acpi_enforce_resources == ENFORCE_RESOURCES_LAX
  923. ? KERN_WARNING : KERN_ERR,
  924. ioport ? "I/O" : "Memory", res->name,
  925. (long long) res->start, (long long) res->end,
  926. res_list_elem->name,
  927. (long long) res_list_elem->start,
  928. (long long) res_list_elem->end);
  929. printk(KERN_INFO "ACPI: Device needs an ACPI driver\n");
  930. }
  931. if (acpi_enforce_resources == ENFORCE_RESOURCES_STRICT)
  932. return -EBUSY;
  933. }
  934. return 0;
  935. }
  936. EXPORT_SYMBOL(acpi_check_resource_conflict);
  937. int acpi_check_region(resource_size_t start, resource_size_t n,
  938. const char *name)
  939. {
  940. struct resource res = {
  941. .start = start,
  942. .end = start + n - 1,
  943. .name = name,
  944. .flags = IORESOURCE_IO,
  945. };
  946. return acpi_check_resource_conflict(&res);
  947. }
  948. EXPORT_SYMBOL(acpi_check_region);
  949. int acpi_check_mem_region(resource_size_t start, resource_size_t n,
  950. const char *name)
  951. {
  952. struct resource res = {
  953. .start = start,
  954. .end = start + n - 1,
  955. .name = name,
  956. .flags = IORESOURCE_MEM,
  957. };
  958. return acpi_check_resource_conflict(&res);
  959. }
  960. EXPORT_SYMBOL(acpi_check_mem_region);
  961. /*
  962. * Acquire a spinlock.
  963. *
  964. * handle is a pointer to the spinlock_t.
  965. */
  966. acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
  967. {
  968. acpi_cpu_flags flags;
  969. spin_lock_irqsave(lockp, flags);
  970. return flags;
  971. }
  972. /*
  973. * Release a spinlock. See above.
  974. */
  975. void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
  976. {
  977. spin_unlock_irqrestore(lockp, flags);
  978. }
  979. #ifndef ACPI_USE_LOCAL_CACHE
  980. /*******************************************************************************
  981. *
  982. * FUNCTION: acpi_os_create_cache
  983. *
  984. * PARAMETERS: name - Ascii name for the cache
  985. * size - Size of each cached object
  986. * depth - Maximum depth of the cache (in objects) <ignored>
  987. * cache - Where the new cache object is returned
  988. *
  989. * RETURN: status
  990. *
  991. * DESCRIPTION: Create a cache object
  992. *
  993. ******************************************************************************/
  994. acpi_status
  995. acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
  996. {
  997. *cache = kmem_cache_create(name, size, 0, 0, NULL);
  998. if (*cache == NULL)
  999. return AE_ERROR;
  1000. else
  1001. return AE_OK;
  1002. }
  1003. /*******************************************************************************
  1004. *
  1005. * FUNCTION: acpi_os_purge_cache
  1006. *
  1007. * PARAMETERS: Cache - Handle to cache object
  1008. *
  1009. * RETURN: Status
  1010. *
  1011. * DESCRIPTION: Free all objects within the requested cache.
  1012. *
  1013. ******************************************************************************/
  1014. acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
  1015. {
  1016. kmem_cache_shrink(cache);
  1017. return (AE_OK);
  1018. }
  1019. /*******************************************************************************
  1020. *
  1021. * FUNCTION: acpi_os_delete_cache
  1022. *
  1023. * PARAMETERS: Cache - Handle to cache object
  1024. *
  1025. * RETURN: Status
  1026. *
  1027. * DESCRIPTION: Free all objects within the requested cache and delete the
  1028. * cache object.
  1029. *
  1030. ******************************************************************************/
  1031. acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
  1032. {
  1033. kmem_cache_destroy(cache);
  1034. return (AE_OK);
  1035. }
  1036. /*******************************************************************************
  1037. *
  1038. * FUNCTION: acpi_os_release_object
  1039. *
  1040. * PARAMETERS: Cache - Handle to cache object
  1041. * Object - The object to be released
  1042. *
  1043. * RETURN: None
  1044. *
  1045. * DESCRIPTION: Release an object to the specified cache. If cache is full,
  1046. * the object is deleted.
  1047. *
  1048. ******************************************************************************/
  1049. acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
  1050. {
  1051. kmem_cache_free(cache, object);
  1052. return (AE_OK);
  1053. }
  1054. /**
  1055. * acpi_dmi_dump - dump DMI slots needed for blacklist entry
  1056. *
  1057. * Returns 0 on success
  1058. */
  1059. static int acpi_dmi_dump(void)
  1060. {
  1061. if (!dmi_available)
  1062. return -1;
  1063. printk(KERN_NOTICE PREFIX "DMI System Vendor: %s\n",
  1064. dmi_get_system_info(DMI_SYS_VENDOR));
  1065. printk(KERN_NOTICE PREFIX "DMI Product Name: %s\n",
  1066. dmi_get_system_info(DMI_PRODUCT_NAME));
  1067. printk(KERN_NOTICE PREFIX "DMI Product Version: %s\n",
  1068. dmi_get_system_info(DMI_PRODUCT_VERSION));
  1069. printk(KERN_NOTICE PREFIX "DMI Board Name: %s\n",
  1070. dmi_get_system_info(DMI_BOARD_NAME));
  1071. printk(KERN_NOTICE PREFIX "DMI BIOS Vendor: %s\n",
  1072. dmi_get_system_info(DMI_BIOS_VENDOR));
  1073. printk(KERN_NOTICE PREFIX "DMI BIOS Date: %s\n",
  1074. dmi_get_system_info(DMI_BIOS_DATE));
  1075. return 0;
  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.dmi) {
  1101. if (acpi_dmi_dump())
  1102. printk(KERN_NOTICE PREFIX
  1103. "[please extract dmidecode output]\n");
  1104. printk(KERN_NOTICE PREFIX
  1105. "Please send DMI info above to "
  1106. "linux-acpi@vger.kernel.org\n");
  1107. }
  1108. if (!osi_linux.known && !osi_linux.cmdline) {
  1109. printk(KERN_NOTICE PREFIX
  1110. "If \"acpi_osi=%sLinux\" works better, "
  1111. "please notify linux-acpi@vger.kernel.org\n",
  1112. osi_linux.enable ? "!" : "");
  1113. }
  1114. if (osi_linux.enable)
  1115. return AE_OK;
  1116. }
  1117. return AE_SUPPORT;
  1118. }
  1119. /******************************************************************************
  1120. *
  1121. * FUNCTION: acpi_os_validate_address
  1122. *
  1123. * PARAMETERS: space_id - ACPI space ID
  1124. * address - Physical address
  1125. * length - Address length
  1126. *
  1127. * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
  1128. * should return AE_AML_ILLEGAL_ADDRESS.
  1129. *
  1130. * DESCRIPTION: Validate a system address via the host OS. Used to validate
  1131. * the addresses accessed by AML operation regions.
  1132. *
  1133. *****************************************************************************/
  1134. acpi_status
  1135. acpi_os_validate_address (
  1136. u8 space_id,
  1137. acpi_physical_address address,
  1138. acpi_size length,
  1139. char *name)
  1140. {
  1141. struct acpi_res_list *res;
  1142. if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
  1143. return AE_OK;
  1144. switch (space_id) {
  1145. case ACPI_ADR_SPACE_SYSTEM_IO:
  1146. case ACPI_ADR_SPACE_SYSTEM_MEMORY:
  1147. /* Only interference checks against SystemIO and SytemMemory
  1148. are needed */
  1149. res = kzalloc(sizeof(struct acpi_res_list), GFP_KERNEL);
  1150. if (!res)
  1151. return AE_OK;
  1152. /* ACPI names are fixed to 4 bytes, still better use strlcpy */
  1153. strlcpy(res->name, name, 5);
  1154. res->start = address;
  1155. res->end = address + length - 1;
  1156. res->resource_type = space_id;
  1157. spin_lock(&acpi_res_lock);
  1158. list_add(&res->resource_list, &resource_list_head);
  1159. spin_unlock(&acpi_res_lock);
  1160. pr_debug("Added %s resource: start: 0x%llx, end: 0x%llx, "
  1161. "name: %s\n", (space_id == ACPI_ADR_SPACE_SYSTEM_IO)
  1162. ? "SystemIO" : "System Memory",
  1163. (unsigned long long)res->start,
  1164. (unsigned long long)res->end,
  1165. res->name);
  1166. break;
  1167. case ACPI_ADR_SPACE_PCI_CONFIG:
  1168. case ACPI_ADR_SPACE_EC:
  1169. case ACPI_ADR_SPACE_SMBUS:
  1170. case ACPI_ADR_SPACE_CMOS:
  1171. case ACPI_ADR_SPACE_PCI_BAR_TARGET:
  1172. case ACPI_ADR_SPACE_DATA_TABLE:
  1173. case ACPI_ADR_SPACE_FIXED_HARDWARE:
  1174. break;
  1175. }
  1176. return AE_OK;
  1177. }
  1178. #endif