osl.c 33 KB

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