osl.c 37 KB

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