osl.c 34 KB

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