osl.c 33 KB

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