osl.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498
  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(current, cpumask_of_cpu(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) {
  594. printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
  595. return;
  596. }
  597. if (dpc->wait)
  598. acpi_os_wait_events_complete(NULL);
  599. dpc->function(dpc->context);
  600. kfree(dpc);
  601. return;
  602. }
  603. /*******************************************************************************
  604. *
  605. * FUNCTION: acpi_os_execute
  606. *
  607. * PARAMETERS: Type - Type of the callback
  608. * Function - Function to be executed
  609. * Context - Function parameters
  610. *
  611. * RETURN: Status
  612. *
  613. * DESCRIPTION: Depending on type, either queues function for deferred execution or
  614. * immediately executes function on a separate thread.
  615. *
  616. ******************************************************************************/
  617. static acpi_status __acpi_os_execute(acpi_execute_type type,
  618. acpi_osd_exec_callback function, void *context, int hp)
  619. {
  620. acpi_status status = AE_OK;
  621. struct acpi_os_dpc *dpc;
  622. struct workqueue_struct *queue;
  623. int ret;
  624. ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
  625. "Scheduling function [%p(%p)] for deferred execution.\n",
  626. function, context));
  627. if (!function)
  628. return AE_BAD_PARAMETER;
  629. /*
  630. * Allocate/initialize DPC structure. Note that this memory will be
  631. * freed by the callee. The kernel handles the work_struct list in a
  632. * way that allows us to also free its memory inside the callee.
  633. * Because we may want to schedule several tasks with different
  634. * parameters we can't use the approach some kernel code uses of
  635. * having a static work_struct.
  636. */
  637. dpc = kmalloc(sizeof(struct acpi_os_dpc), GFP_ATOMIC);
  638. if (!dpc)
  639. return AE_NO_MEMORY;
  640. dpc->function = function;
  641. dpc->context = context;
  642. /*
  643. * We can't run hotplug code in keventd_wq/kacpid_wq/kacpid_notify_wq
  644. * because the hotplug code may call driver .remove() functions,
  645. * which invoke flush_scheduled_work/acpi_os_wait_events_complete
  646. * to flush these workqueues.
  647. */
  648. queue = hp ? kacpi_hotplug_wq :
  649. (type == OSL_NOTIFY_HANDLER ? kacpi_notify_wq : kacpid_wq);
  650. dpc->wait = hp ? 1 : 0;
  651. INIT_WORK(&dpc->work, acpi_os_execute_deferred);
  652. ret = queue_work(queue, &dpc->work);
  653. if (!ret) {
  654. printk(KERN_ERR PREFIX
  655. "Call to queue_work() failed.\n");
  656. status = AE_ERROR;
  657. kfree(dpc);
  658. }
  659. return status;
  660. }
  661. acpi_status acpi_os_execute(acpi_execute_type type,
  662. acpi_osd_exec_callback function, void *context)
  663. {
  664. return __acpi_os_execute(type, function, context, 0);
  665. }
  666. EXPORT_SYMBOL(acpi_os_execute);
  667. acpi_status acpi_os_hotplug_execute(acpi_osd_exec_callback function,
  668. void *context)
  669. {
  670. return __acpi_os_execute(0, function, context, 1);
  671. }
  672. void acpi_os_wait_events_complete(void *context)
  673. {
  674. flush_workqueue(kacpid_wq);
  675. flush_workqueue(kacpi_notify_wq);
  676. }
  677. EXPORT_SYMBOL(acpi_os_wait_events_complete);
  678. /*
  679. * Allocate the memory for a spinlock and initialize it.
  680. */
  681. acpi_status acpi_os_create_lock(acpi_spinlock * handle)
  682. {
  683. spin_lock_init(*handle);
  684. return AE_OK;
  685. }
  686. /*
  687. * Deallocate the memory for a spinlock.
  688. */
  689. void acpi_os_delete_lock(acpi_spinlock handle)
  690. {
  691. return;
  692. }
  693. acpi_status
  694. acpi_os_create_semaphore(u32 max_units, u32 initial_units, acpi_handle * handle)
  695. {
  696. struct semaphore *sem = NULL;
  697. sem = acpi_os_allocate(sizeof(struct semaphore));
  698. if (!sem)
  699. return AE_NO_MEMORY;
  700. memset(sem, 0, sizeof(struct semaphore));
  701. sema_init(sem, initial_units);
  702. *handle = (acpi_handle *) sem;
  703. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Creating semaphore[%p|%d].\n",
  704. *handle, initial_units));
  705. return AE_OK;
  706. }
  707. /*
  708. * TODO: A better way to delete semaphores? Linux doesn't have a
  709. * 'delete_semaphore()' function -- may result in an invalid
  710. * pointer dereference for non-synchronized consumers. Should
  711. * we at least check for blocked threads and signal/cancel them?
  712. */
  713. acpi_status acpi_os_delete_semaphore(acpi_handle handle)
  714. {
  715. struct semaphore *sem = (struct semaphore *)handle;
  716. if (!sem)
  717. return AE_BAD_PARAMETER;
  718. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Deleting semaphore[%p].\n", handle));
  719. BUG_ON(!list_empty(&sem->wait_list));
  720. kfree(sem);
  721. sem = NULL;
  722. return AE_OK;
  723. }
  724. /*
  725. * TODO: Support for units > 1?
  726. */
  727. acpi_status acpi_os_wait_semaphore(acpi_handle handle, u32 units, u16 timeout)
  728. {
  729. acpi_status status = AE_OK;
  730. struct semaphore *sem = (struct semaphore *)handle;
  731. long jiffies;
  732. int ret = 0;
  733. if (!sem || (units < 1))
  734. return AE_BAD_PARAMETER;
  735. if (units > 1)
  736. return AE_SUPPORT;
  737. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Waiting for semaphore[%p|%d|%d]\n",
  738. handle, units, timeout));
  739. if (timeout == ACPI_WAIT_FOREVER)
  740. jiffies = MAX_SCHEDULE_TIMEOUT;
  741. else
  742. jiffies = msecs_to_jiffies(timeout);
  743. ret = down_timeout(sem, jiffies);
  744. if (ret)
  745. status = AE_TIME;
  746. if (ACPI_FAILURE(status)) {
  747. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
  748. "Failed to acquire semaphore[%p|%d|%d], %s",
  749. handle, units, timeout,
  750. acpi_format_exception(status)));
  751. } else {
  752. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
  753. "Acquired semaphore[%p|%d|%d]", handle,
  754. units, timeout));
  755. }
  756. return status;
  757. }
  758. /*
  759. * TODO: Support for units > 1?
  760. */
  761. acpi_status acpi_os_signal_semaphore(acpi_handle handle, u32 units)
  762. {
  763. struct semaphore *sem = (struct semaphore *)handle;
  764. if (!sem || (units < 1))
  765. return AE_BAD_PARAMETER;
  766. if (units > 1)
  767. return AE_SUPPORT;
  768. ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, "Signaling semaphore[%p|%d]\n", handle,
  769. units));
  770. up(sem);
  771. return AE_OK;
  772. }
  773. #ifdef ACPI_FUTURE_USAGE
  774. u32 acpi_os_get_line(char *buffer)
  775. {
  776. #ifdef ENABLE_DEBUGGER
  777. if (acpi_in_debugger) {
  778. u32 chars;
  779. kdb_read(buffer, sizeof(line_buf));
  780. /* remove the CR kdb includes */
  781. chars = strlen(buffer) - 1;
  782. buffer[chars] = '\0';
  783. }
  784. #endif
  785. return 0;
  786. }
  787. #endif /* ACPI_FUTURE_USAGE */
  788. acpi_status acpi_os_signal(u32 function, void *info)
  789. {
  790. switch (function) {
  791. case ACPI_SIGNAL_FATAL:
  792. printk(KERN_ERR PREFIX "Fatal opcode executed\n");
  793. break;
  794. case ACPI_SIGNAL_BREAKPOINT:
  795. /*
  796. * AML Breakpoint
  797. * ACPI spec. says to treat it as a NOP unless
  798. * you are debugging. So if/when we integrate
  799. * AML debugger into the kernel debugger its
  800. * hook will go here. But until then it is
  801. * not useful to print anything on breakpoints.
  802. */
  803. break;
  804. default:
  805. break;
  806. }
  807. return AE_OK;
  808. }
  809. static int __init acpi_os_name_setup(char *str)
  810. {
  811. char *p = acpi_os_name;
  812. int count = ACPI_MAX_OVERRIDE_LEN - 1;
  813. if (!str || !*str)
  814. return 0;
  815. for (; count-- && str && *str; str++) {
  816. if (isalnum(*str) || *str == ' ' || *str == ':')
  817. *p++ = *str;
  818. else if (*str == '\'' || *str == '"')
  819. continue;
  820. else
  821. break;
  822. }
  823. *p = 0;
  824. return 1;
  825. }
  826. __setup("acpi_os_name=", acpi_os_name_setup);
  827. static void __init set_osi_linux(unsigned int enable)
  828. {
  829. if (osi_linux.enable != enable) {
  830. osi_linux.enable = enable;
  831. printk(KERN_NOTICE PREFIX "%sed _OSI(Linux)\n",
  832. enable ? "Add": "Delet");
  833. }
  834. return;
  835. }
  836. static void __init acpi_cmdline_osi_linux(unsigned int enable)
  837. {
  838. osi_linux.cmdline = 1; /* cmdline set the default */
  839. set_osi_linux(enable);
  840. return;
  841. }
  842. void __init acpi_dmi_osi_linux(int enable, const struct dmi_system_id *d)
  843. {
  844. osi_linux.dmi = 1; /* DMI knows that this box asks OSI(Linux) */
  845. printk(KERN_NOTICE PREFIX "DMI detected: %s\n", d->ident);
  846. if (enable == -1)
  847. return;
  848. osi_linux.known = 1; /* DMI knows which OSI(Linux) default needed */
  849. set_osi_linux(enable);
  850. return;
  851. }
  852. /*
  853. * Modify the list of "OS Interfaces" reported to BIOS via _OSI
  854. *
  855. * empty string disables _OSI
  856. * string starting with '!' disables that string
  857. * otherwise string is added to list, augmenting built-in strings
  858. */
  859. int __init acpi_osi_setup(char *str)
  860. {
  861. if (str == NULL || *str == '\0') {
  862. printk(KERN_INFO PREFIX "_OSI method disabled\n");
  863. acpi_gbl_create_osi_method = FALSE;
  864. } else if (!strcmp("!Linux", str)) {
  865. acpi_cmdline_osi_linux(0); /* !enable */
  866. } else if (*str == '!') {
  867. if (acpi_osi_invalidate(++str) == AE_OK)
  868. printk(KERN_INFO PREFIX "Deleted _OSI(%s)\n", str);
  869. } else if (!strcmp("Linux", str)) {
  870. acpi_cmdline_osi_linux(1); /* enable */
  871. } else if (*osi_additional_string == '\0') {
  872. strncpy(osi_additional_string, str, OSI_STRING_LENGTH_MAX);
  873. printk(KERN_INFO PREFIX "Added _OSI(%s)\n", str);
  874. }
  875. return 1;
  876. }
  877. __setup("acpi_osi=", acpi_osi_setup);
  878. /* enable serialization to combat AE_ALREADY_EXISTS errors */
  879. static int __init acpi_serialize_setup(char *str)
  880. {
  881. printk(KERN_INFO PREFIX "serialize enabled\n");
  882. acpi_gbl_all_methods_serialized = TRUE;
  883. return 1;
  884. }
  885. __setup("acpi_serialize", acpi_serialize_setup);
  886. /*
  887. * Wake and Run-Time GPES are expected to be separate.
  888. * We disable wake-GPEs at run-time to prevent spurious
  889. * interrupts.
  890. *
  891. * However, if a system exists that shares Wake and
  892. * Run-time events on the same GPE this flag is available
  893. * to tell Linux to keep the wake-time GPEs enabled at run-time.
  894. */
  895. static int __init acpi_wake_gpes_always_on_setup(char *str)
  896. {
  897. printk(KERN_INFO PREFIX "wake GPEs not disabled\n");
  898. acpi_gbl_leave_wake_gpes_disabled = FALSE;
  899. return 1;
  900. }
  901. __setup("acpi_wake_gpes_always_on", acpi_wake_gpes_always_on_setup);
  902. /* Check of resource interference between native drivers and ACPI
  903. * OperationRegions (SystemIO and System Memory only).
  904. * IO ports and memory declared in ACPI might be used by the ACPI subsystem
  905. * in arbitrary AML code and can interfere with legacy drivers.
  906. * acpi_enforce_resources= can be set to:
  907. *
  908. * - strict (default) (2)
  909. * -> further driver trying to access the resources will not load
  910. * - lax (1)
  911. * -> further driver trying to access the resources will load, but you
  912. * get a system message that something might go wrong...
  913. *
  914. * - no (0)
  915. * -> ACPI Operation Region resources will not be registered
  916. *
  917. */
  918. #define ENFORCE_RESOURCES_STRICT 2
  919. #define ENFORCE_RESOURCES_LAX 1
  920. #define ENFORCE_RESOURCES_NO 0
  921. static unsigned int acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
  922. static int __init acpi_enforce_resources_setup(char *str)
  923. {
  924. if (str == NULL || *str == '\0')
  925. return 0;
  926. if (!strcmp("strict", str))
  927. acpi_enforce_resources = ENFORCE_RESOURCES_STRICT;
  928. else if (!strcmp("lax", str))
  929. acpi_enforce_resources = ENFORCE_RESOURCES_LAX;
  930. else if (!strcmp("no", str))
  931. acpi_enforce_resources = ENFORCE_RESOURCES_NO;
  932. return 1;
  933. }
  934. __setup("acpi_enforce_resources=", acpi_enforce_resources_setup);
  935. /* Check for resource conflicts between ACPI OperationRegions and native
  936. * drivers */
  937. int acpi_check_resource_conflict(struct resource *res)
  938. {
  939. struct acpi_res_list *res_list_elem;
  940. int ioport;
  941. int clash = 0;
  942. if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
  943. return 0;
  944. if (!(res->flags & IORESOURCE_IO) && !(res->flags & IORESOURCE_MEM))
  945. return 0;
  946. ioport = res->flags & IORESOURCE_IO;
  947. spin_lock(&acpi_res_lock);
  948. list_for_each_entry(res_list_elem, &resource_list_head,
  949. resource_list) {
  950. if (ioport && (res_list_elem->resource_type
  951. != ACPI_ADR_SPACE_SYSTEM_IO))
  952. continue;
  953. if (!ioport && (res_list_elem->resource_type
  954. != ACPI_ADR_SPACE_SYSTEM_MEMORY))
  955. continue;
  956. if (res->end < res_list_elem->start
  957. || res_list_elem->end < res->start)
  958. continue;
  959. clash = 1;
  960. break;
  961. }
  962. spin_unlock(&acpi_res_lock);
  963. if (clash) {
  964. if (acpi_enforce_resources != ENFORCE_RESOURCES_NO) {
  965. printk("%sACPI: %s resource %s [0x%llx-0x%llx]"
  966. " conflicts with ACPI region %s"
  967. " [0x%llx-0x%llx]\n",
  968. acpi_enforce_resources == ENFORCE_RESOURCES_LAX
  969. ? KERN_WARNING : KERN_ERR,
  970. ioport ? "I/O" : "Memory", res->name,
  971. (long long) res->start, (long long) res->end,
  972. res_list_elem->name,
  973. (long long) res_list_elem->start,
  974. (long long) res_list_elem->end);
  975. printk(KERN_INFO "ACPI: Device needs an ACPI driver\n");
  976. }
  977. if (acpi_enforce_resources == ENFORCE_RESOURCES_STRICT)
  978. return -EBUSY;
  979. }
  980. return 0;
  981. }
  982. EXPORT_SYMBOL(acpi_check_resource_conflict);
  983. int acpi_check_region(resource_size_t start, resource_size_t n,
  984. const char *name)
  985. {
  986. struct resource res = {
  987. .start = start,
  988. .end = start + n - 1,
  989. .name = name,
  990. .flags = IORESOURCE_IO,
  991. };
  992. return acpi_check_resource_conflict(&res);
  993. }
  994. EXPORT_SYMBOL(acpi_check_region);
  995. int acpi_check_mem_region(resource_size_t start, resource_size_t n,
  996. const char *name)
  997. {
  998. struct resource res = {
  999. .start = start,
  1000. .end = start + n - 1,
  1001. .name = name,
  1002. .flags = IORESOURCE_MEM,
  1003. };
  1004. return acpi_check_resource_conflict(&res);
  1005. }
  1006. EXPORT_SYMBOL(acpi_check_mem_region);
  1007. /*
  1008. * Acquire a spinlock.
  1009. *
  1010. * handle is a pointer to the spinlock_t.
  1011. */
  1012. acpi_cpu_flags acpi_os_acquire_lock(acpi_spinlock lockp)
  1013. {
  1014. acpi_cpu_flags flags;
  1015. spin_lock_irqsave(lockp, flags);
  1016. return flags;
  1017. }
  1018. /*
  1019. * Release a spinlock. See above.
  1020. */
  1021. void acpi_os_release_lock(acpi_spinlock lockp, acpi_cpu_flags flags)
  1022. {
  1023. spin_unlock_irqrestore(lockp, flags);
  1024. }
  1025. #ifndef ACPI_USE_LOCAL_CACHE
  1026. /*******************************************************************************
  1027. *
  1028. * FUNCTION: acpi_os_create_cache
  1029. *
  1030. * PARAMETERS: name - Ascii name for the cache
  1031. * size - Size of each cached object
  1032. * depth - Maximum depth of the cache (in objects) <ignored>
  1033. * cache - Where the new cache object is returned
  1034. *
  1035. * RETURN: status
  1036. *
  1037. * DESCRIPTION: Create a cache object
  1038. *
  1039. ******************************************************************************/
  1040. acpi_status
  1041. acpi_os_create_cache(char *name, u16 size, u16 depth, acpi_cache_t ** cache)
  1042. {
  1043. *cache = kmem_cache_create(name, size, 0, 0, NULL);
  1044. if (*cache == NULL)
  1045. return AE_ERROR;
  1046. else
  1047. return AE_OK;
  1048. }
  1049. /*******************************************************************************
  1050. *
  1051. * FUNCTION: acpi_os_purge_cache
  1052. *
  1053. * PARAMETERS: Cache - Handle to cache object
  1054. *
  1055. * RETURN: Status
  1056. *
  1057. * DESCRIPTION: Free all objects within the requested cache.
  1058. *
  1059. ******************************************************************************/
  1060. acpi_status acpi_os_purge_cache(acpi_cache_t * cache)
  1061. {
  1062. kmem_cache_shrink(cache);
  1063. return (AE_OK);
  1064. }
  1065. /*******************************************************************************
  1066. *
  1067. * FUNCTION: acpi_os_delete_cache
  1068. *
  1069. * PARAMETERS: Cache - Handle to cache object
  1070. *
  1071. * RETURN: Status
  1072. *
  1073. * DESCRIPTION: Free all objects within the requested cache and delete the
  1074. * cache object.
  1075. *
  1076. ******************************************************************************/
  1077. acpi_status acpi_os_delete_cache(acpi_cache_t * cache)
  1078. {
  1079. kmem_cache_destroy(cache);
  1080. return (AE_OK);
  1081. }
  1082. /*******************************************************************************
  1083. *
  1084. * FUNCTION: acpi_os_release_object
  1085. *
  1086. * PARAMETERS: Cache - Handle to cache object
  1087. * Object - The object to be released
  1088. *
  1089. * RETURN: None
  1090. *
  1091. * DESCRIPTION: Release an object to the specified cache. If cache is full,
  1092. * the object is deleted.
  1093. *
  1094. ******************************************************************************/
  1095. acpi_status acpi_os_release_object(acpi_cache_t * cache, void *object)
  1096. {
  1097. kmem_cache_free(cache, object);
  1098. return (AE_OK);
  1099. }
  1100. /******************************************************************************
  1101. *
  1102. * FUNCTION: acpi_os_validate_interface
  1103. *
  1104. * PARAMETERS: interface - Requested interface to be validated
  1105. *
  1106. * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
  1107. *
  1108. * DESCRIPTION: Match an interface string to the interfaces supported by the
  1109. * host. Strings originate from an AML call to the _OSI method.
  1110. *
  1111. *****************************************************************************/
  1112. acpi_status
  1113. acpi_os_validate_interface (char *interface)
  1114. {
  1115. if (!strncmp(osi_additional_string, interface, OSI_STRING_LENGTH_MAX))
  1116. return AE_OK;
  1117. if (!strcmp("Linux", interface)) {
  1118. printk(KERN_NOTICE PREFIX
  1119. "BIOS _OSI(Linux) query %s%s\n",
  1120. osi_linux.enable ? "honored" : "ignored",
  1121. osi_linux.cmdline ? " via cmdline" :
  1122. osi_linux.dmi ? " via DMI" : "");
  1123. if (osi_linux.enable)
  1124. return AE_OK;
  1125. }
  1126. return AE_SUPPORT;
  1127. }
  1128. static inline int acpi_res_list_add(struct acpi_res_list *res)
  1129. {
  1130. struct acpi_res_list *res_list_elem;
  1131. list_for_each_entry(res_list_elem, &resource_list_head,
  1132. resource_list) {
  1133. if (res->resource_type == res_list_elem->resource_type &&
  1134. res->start == res_list_elem->start &&
  1135. res->end == res_list_elem->end) {
  1136. /*
  1137. * The Region(addr,len) already exist in the list,
  1138. * just increase the count
  1139. */
  1140. res_list_elem->count++;
  1141. return 0;
  1142. }
  1143. }
  1144. res->count = 1;
  1145. list_add(&res->resource_list, &resource_list_head);
  1146. return 1;
  1147. }
  1148. static inline void acpi_res_list_del(struct acpi_res_list *res)
  1149. {
  1150. struct acpi_res_list *res_list_elem;
  1151. list_for_each_entry(res_list_elem, &resource_list_head,
  1152. resource_list) {
  1153. if (res->resource_type == res_list_elem->resource_type &&
  1154. res->start == res_list_elem->start &&
  1155. res->end == res_list_elem->end) {
  1156. /*
  1157. * If the res count is decreased to 0,
  1158. * remove and free it
  1159. */
  1160. if (--res_list_elem->count == 0) {
  1161. list_del(&res_list_elem->resource_list);
  1162. kfree(res_list_elem);
  1163. }
  1164. return;
  1165. }
  1166. }
  1167. }
  1168. acpi_status
  1169. acpi_os_invalidate_address(
  1170. u8 space_id,
  1171. acpi_physical_address address,
  1172. acpi_size length)
  1173. {
  1174. struct acpi_res_list res;
  1175. switch (space_id) {
  1176. case ACPI_ADR_SPACE_SYSTEM_IO:
  1177. case ACPI_ADR_SPACE_SYSTEM_MEMORY:
  1178. /* Only interference checks against SystemIO and SytemMemory
  1179. are needed */
  1180. res.start = address;
  1181. res.end = address + length - 1;
  1182. res.resource_type = space_id;
  1183. spin_lock(&acpi_res_lock);
  1184. acpi_res_list_del(&res);
  1185. spin_unlock(&acpi_res_lock);
  1186. break;
  1187. case ACPI_ADR_SPACE_PCI_CONFIG:
  1188. case ACPI_ADR_SPACE_EC:
  1189. case ACPI_ADR_SPACE_SMBUS:
  1190. case ACPI_ADR_SPACE_CMOS:
  1191. case ACPI_ADR_SPACE_PCI_BAR_TARGET:
  1192. case ACPI_ADR_SPACE_DATA_TABLE:
  1193. case ACPI_ADR_SPACE_FIXED_HARDWARE:
  1194. break;
  1195. }
  1196. return AE_OK;
  1197. }
  1198. /******************************************************************************
  1199. *
  1200. * FUNCTION: acpi_os_validate_address
  1201. *
  1202. * PARAMETERS: space_id - ACPI space ID
  1203. * address - Physical address
  1204. * length - Address length
  1205. *
  1206. * RETURN: AE_OK if address/length is valid for the space_id. Otherwise,
  1207. * should return AE_AML_ILLEGAL_ADDRESS.
  1208. *
  1209. * DESCRIPTION: Validate a system address via the host OS. Used to validate
  1210. * the addresses accessed by AML operation regions.
  1211. *
  1212. *****************************************************************************/
  1213. acpi_status
  1214. acpi_os_validate_address (
  1215. u8 space_id,
  1216. acpi_physical_address address,
  1217. acpi_size length,
  1218. char *name)
  1219. {
  1220. struct acpi_res_list *res;
  1221. int added;
  1222. if (acpi_enforce_resources == ENFORCE_RESOURCES_NO)
  1223. return AE_OK;
  1224. switch (space_id) {
  1225. case ACPI_ADR_SPACE_SYSTEM_IO:
  1226. case ACPI_ADR_SPACE_SYSTEM_MEMORY:
  1227. /* Only interference checks against SystemIO and SytemMemory
  1228. are needed */
  1229. res = kzalloc(sizeof(struct acpi_res_list), GFP_KERNEL);
  1230. if (!res)
  1231. return AE_OK;
  1232. /* ACPI names are fixed to 4 bytes, still better use strlcpy */
  1233. strlcpy(res->name, name, 5);
  1234. res->start = address;
  1235. res->end = address + length - 1;
  1236. res->resource_type = space_id;
  1237. spin_lock(&acpi_res_lock);
  1238. added = acpi_res_list_add(res);
  1239. spin_unlock(&acpi_res_lock);
  1240. pr_debug("%s %s resource: start: 0x%llx, end: 0x%llx, "
  1241. "name: %s\n", added ? "Added" : "Already exist",
  1242. (space_id == ACPI_ADR_SPACE_SYSTEM_IO)
  1243. ? "SystemIO" : "System Memory",
  1244. (unsigned long long)res->start,
  1245. (unsigned long long)res->end,
  1246. res->name);
  1247. if (!added)
  1248. kfree(res);
  1249. break;
  1250. case ACPI_ADR_SPACE_PCI_CONFIG:
  1251. case ACPI_ADR_SPACE_EC:
  1252. case ACPI_ADR_SPACE_SMBUS:
  1253. case ACPI_ADR_SPACE_CMOS:
  1254. case ACPI_ADR_SPACE_PCI_BAR_TARGET:
  1255. case ACPI_ADR_SPACE_DATA_TABLE:
  1256. case ACPI_ADR_SPACE_FIXED_HARDWARE:
  1257. break;
  1258. }
  1259. return AE_OK;
  1260. }
  1261. #endif