osl.c 36 KB

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