osl.c 36 KB

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