osl.c 35 KB

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