dcdbas.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. /*
  2. * dcdbas.c: Dell Systems Management Base Driver
  3. *
  4. * The Dell Systems Management Base Driver provides a sysfs interface for
  5. * systems management software to perform System Management Interrupts (SMIs)
  6. * and Host Control Actions (power cycle or power off after OS shutdown) on
  7. * Dell systems.
  8. *
  9. * See Documentation/dcdbas.txt for more information.
  10. *
  11. * Copyright (C) 1995-2006 Dell Inc.
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License v2.0 as published by
  15. * the Free Software Foundation.
  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. #include <linux/platform_device.h>
  23. #include <linux/acpi.h>
  24. #include <linux/dma-mapping.h>
  25. #include <linux/errno.h>
  26. #include <linux/cpu.h>
  27. #include <linux/gfp.h>
  28. #include <linux/init.h>
  29. #include <linux/io.h>
  30. #include <linux/kernel.h>
  31. #include <linux/mc146818rtc.h>
  32. #include <linux/module.h>
  33. #include <linux/reboot.h>
  34. #include <linux/sched.h>
  35. #include <linux/smp.h>
  36. #include <linux/spinlock.h>
  37. #include <linux/string.h>
  38. #include <linux/types.h>
  39. #include <linux/mutex.h>
  40. #include "dcdbas.h"
  41. #define DRIVER_NAME "dcdbas"
  42. #define DRIVER_VERSION "5.6.0-3.3"
  43. #define DRIVER_DESCRIPTION "Dell Systems Management Base Driver"
  44. static struct platform_device *dcdbas_pdev;
  45. static u8 *smi_data_buf;
  46. static dma_addr_t smi_data_buf_handle;
  47. static unsigned long smi_data_buf_size;
  48. static unsigned long max_smi_data_buf_size = MAX_SMI_DATA_BUF_SIZE;
  49. static u32 smi_data_buf_phys_addr;
  50. static DEFINE_MUTEX(smi_data_lock);
  51. static u8 *eps_buffer;
  52. static unsigned int host_control_action;
  53. static unsigned int host_control_smi_type;
  54. static unsigned int host_control_on_shutdown;
  55. static bool wsmt_enabled;
  56. /**
  57. * smi_data_buf_free: free SMI data buffer
  58. */
  59. static void smi_data_buf_free(void)
  60. {
  61. if (!smi_data_buf || wsmt_enabled)
  62. return;
  63. dev_dbg(&dcdbas_pdev->dev, "%s: phys: %x size: %lu\n",
  64. __func__, smi_data_buf_phys_addr, smi_data_buf_size);
  65. dma_free_coherent(&dcdbas_pdev->dev, smi_data_buf_size, smi_data_buf,
  66. smi_data_buf_handle);
  67. smi_data_buf = NULL;
  68. smi_data_buf_handle = 0;
  69. smi_data_buf_phys_addr = 0;
  70. smi_data_buf_size = 0;
  71. }
  72. /**
  73. * smi_data_buf_realloc: grow SMI data buffer if needed
  74. */
  75. static int smi_data_buf_realloc(unsigned long size)
  76. {
  77. void *buf;
  78. dma_addr_t handle;
  79. if (smi_data_buf_size >= size)
  80. return 0;
  81. if (size > max_smi_data_buf_size)
  82. return -EINVAL;
  83. /* new buffer is needed */
  84. buf = dma_alloc_coherent(&dcdbas_pdev->dev, size, &handle, GFP_KERNEL);
  85. if (!buf) {
  86. dev_dbg(&dcdbas_pdev->dev,
  87. "%s: failed to allocate memory size %lu\n",
  88. __func__, size);
  89. return -ENOMEM;
  90. }
  91. /* memory zeroed by dma_alloc_coherent */
  92. if (smi_data_buf)
  93. memcpy(buf, smi_data_buf, smi_data_buf_size);
  94. /* free any existing buffer */
  95. smi_data_buf_free();
  96. /* set up new buffer for use */
  97. smi_data_buf = buf;
  98. smi_data_buf_handle = handle;
  99. smi_data_buf_phys_addr = (u32) virt_to_phys(buf);
  100. smi_data_buf_size = size;
  101. dev_dbg(&dcdbas_pdev->dev, "%s: phys: %x size: %lu\n",
  102. __func__, smi_data_buf_phys_addr, smi_data_buf_size);
  103. return 0;
  104. }
  105. static ssize_t smi_data_buf_phys_addr_show(struct device *dev,
  106. struct device_attribute *attr,
  107. char *buf)
  108. {
  109. return sprintf(buf, "%x\n", smi_data_buf_phys_addr);
  110. }
  111. static ssize_t smi_data_buf_size_show(struct device *dev,
  112. struct device_attribute *attr,
  113. char *buf)
  114. {
  115. return sprintf(buf, "%lu\n", smi_data_buf_size);
  116. }
  117. static ssize_t smi_data_buf_size_store(struct device *dev,
  118. struct device_attribute *attr,
  119. const char *buf, size_t count)
  120. {
  121. unsigned long buf_size;
  122. ssize_t ret;
  123. buf_size = simple_strtoul(buf, NULL, 10);
  124. /* make sure SMI data buffer is at least buf_size */
  125. mutex_lock(&smi_data_lock);
  126. ret = smi_data_buf_realloc(buf_size);
  127. mutex_unlock(&smi_data_lock);
  128. if (ret)
  129. return ret;
  130. return count;
  131. }
  132. static ssize_t smi_data_read(struct file *filp, struct kobject *kobj,
  133. struct bin_attribute *bin_attr,
  134. char *buf, loff_t pos, size_t count)
  135. {
  136. ssize_t ret;
  137. mutex_lock(&smi_data_lock);
  138. ret = memory_read_from_buffer(buf, count, &pos, smi_data_buf,
  139. smi_data_buf_size);
  140. mutex_unlock(&smi_data_lock);
  141. return ret;
  142. }
  143. static ssize_t smi_data_write(struct file *filp, struct kobject *kobj,
  144. struct bin_attribute *bin_attr,
  145. char *buf, loff_t pos, size_t count)
  146. {
  147. ssize_t ret;
  148. if ((pos + count) > max_smi_data_buf_size)
  149. return -EINVAL;
  150. mutex_lock(&smi_data_lock);
  151. ret = smi_data_buf_realloc(pos + count);
  152. if (ret)
  153. goto out;
  154. memcpy(smi_data_buf + pos, buf, count);
  155. ret = count;
  156. out:
  157. mutex_unlock(&smi_data_lock);
  158. return ret;
  159. }
  160. static ssize_t host_control_action_show(struct device *dev,
  161. struct device_attribute *attr,
  162. char *buf)
  163. {
  164. return sprintf(buf, "%u\n", host_control_action);
  165. }
  166. static ssize_t host_control_action_store(struct device *dev,
  167. struct device_attribute *attr,
  168. const char *buf, size_t count)
  169. {
  170. ssize_t ret;
  171. /* make sure buffer is available for host control command */
  172. mutex_lock(&smi_data_lock);
  173. ret = smi_data_buf_realloc(sizeof(struct apm_cmd));
  174. mutex_unlock(&smi_data_lock);
  175. if (ret)
  176. return ret;
  177. host_control_action = simple_strtoul(buf, NULL, 10);
  178. return count;
  179. }
  180. static ssize_t host_control_smi_type_show(struct device *dev,
  181. struct device_attribute *attr,
  182. char *buf)
  183. {
  184. return sprintf(buf, "%u\n", host_control_smi_type);
  185. }
  186. static ssize_t host_control_smi_type_store(struct device *dev,
  187. struct device_attribute *attr,
  188. const char *buf, size_t count)
  189. {
  190. host_control_smi_type = simple_strtoul(buf, NULL, 10);
  191. return count;
  192. }
  193. static ssize_t host_control_on_shutdown_show(struct device *dev,
  194. struct device_attribute *attr,
  195. char *buf)
  196. {
  197. return sprintf(buf, "%u\n", host_control_on_shutdown);
  198. }
  199. static ssize_t host_control_on_shutdown_store(struct device *dev,
  200. struct device_attribute *attr,
  201. const char *buf, size_t count)
  202. {
  203. host_control_on_shutdown = simple_strtoul(buf, NULL, 10);
  204. return count;
  205. }
  206. static int raise_smi(void *par)
  207. {
  208. struct smi_cmd *smi_cmd = par;
  209. if (smp_processor_id() != 0) {
  210. dev_dbg(&dcdbas_pdev->dev, "%s: failed to get CPU 0\n",
  211. __func__);
  212. return -EBUSY;
  213. }
  214. /* generate SMI */
  215. /* inb to force posted write through and make SMI happen now */
  216. asm volatile (
  217. "outb %b0,%w1\n"
  218. "inb %w1"
  219. : /* no output args */
  220. : "a" (smi_cmd->command_code),
  221. "d" (smi_cmd->command_address),
  222. "b" (smi_cmd->ebx),
  223. "c" (smi_cmd->ecx)
  224. : "memory"
  225. );
  226. return 0;
  227. }
  228. /**
  229. * dcdbas_smi_request: generate SMI request
  230. *
  231. * Called with smi_data_lock.
  232. */
  233. int dcdbas_smi_request(struct smi_cmd *smi_cmd)
  234. {
  235. int ret;
  236. if (smi_cmd->magic != SMI_CMD_MAGIC) {
  237. dev_info(&dcdbas_pdev->dev, "%s: invalid magic value\n",
  238. __func__);
  239. return -EBADR;
  240. }
  241. /* SMI requires CPU 0 */
  242. get_online_cpus();
  243. ret = smp_call_on_cpu(0, raise_smi, smi_cmd, true);
  244. put_online_cpus();
  245. return ret;
  246. }
  247. /**
  248. * smi_request_store:
  249. *
  250. * The valid values are:
  251. * 0: zero SMI data buffer
  252. * 1: generate calling interface SMI
  253. * 2: generate raw SMI
  254. *
  255. * User application writes smi_cmd to smi_data before telling driver
  256. * to generate SMI.
  257. */
  258. static ssize_t smi_request_store(struct device *dev,
  259. struct device_attribute *attr,
  260. const char *buf, size_t count)
  261. {
  262. struct smi_cmd *smi_cmd;
  263. unsigned long val = simple_strtoul(buf, NULL, 10);
  264. ssize_t ret;
  265. mutex_lock(&smi_data_lock);
  266. if (smi_data_buf_size < sizeof(struct smi_cmd)) {
  267. ret = -ENODEV;
  268. goto out;
  269. }
  270. smi_cmd = (struct smi_cmd *)smi_data_buf;
  271. switch (val) {
  272. case 2:
  273. /* Raw SMI */
  274. ret = dcdbas_smi_request(smi_cmd);
  275. if (!ret)
  276. ret = count;
  277. break;
  278. case 1:
  279. /*
  280. * Calling Interface SMI
  281. *
  282. * Provide physical address of command buffer field within
  283. * the struct smi_cmd to BIOS.
  284. *
  285. * Because the address that smi_cmd (smi_data_buf) points to
  286. * will be from memremap() of a non-memory address if WSMT
  287. * is present, we can't use virt_to_phys() on smi_cmd, so
  288. * we have to use the physical address that was saved when
  289. * the virtual address for smi_cmd was received.
  290. */
  291. smi_cmd->ebx = smi_data_buf_phys_addr +
  292. offsetof(struct smi_cmd, command_buffer);
  293. ret = dcdbas_smi_request(smi_cmd);
  294. if (!ret)
  295. ret = count;
  296. break;
  297. case 0:
  298. memset(smi_data_buf, 0, smi_data_buf_size);
  299. ret = count;
  300. break;
  301. default:
  302. ret = -EINVAL;
  303. break;
  304. }
  305. out:
  306. mutex_unlock(&smi_data_lock);
  307. return ret;
  308. }
  309. EXPORT_SYMBOL(dcdbas_smi_request);
  310. /**
  311. * host_control_smi: generate host control SMI
  312. *
  313. * Caller must set up the host control command in smi_data_buf.
  314. */
  315. static int host_control_smi(void)
  316. {
  317. struct apm_cmd *apm_cmd;
  318. u8 *data;
  319. unsigned long flags;
  320. u32 num_ticks;
  321. s8 cmd_status;
  322. u8 index;
  323. apm_cmd = (struct apm_cmd *)smi_data_buf;
  324. apm_cmd->status = ESM_STATUS_CMD_UNSUCCESSFUL;
  325. switch (host_control_smi_type) {
  326. case HC_SMITYPE_TYPE1:
  327. spin_lock_irqsave(&rtc_lock, flags);
  328. /* write SMI data buffer physical address */
  329. data = (u8 *)&smi_data_buf_phys_addr;
  330. for (index = PE1300_CMOS_CMD_STRUCT_PTR;
  331. index < (PE1300_CMOS_CMD_STRUCT_PTR + 4);
  332. index++, data++) {
  333. outb(index,
  334. (CMOS_BASE_PORT + CMOS_PAGE2_INDEX_PORT_PIIX4));
  335. outb(*data,
  336. (CMOS_BASE_PORT + CMOS_PAGE2_DATA_PORT_PIIX4));
  337. }
  338. /* first set status to -1 as called by spec */
  339. cmd_status = ESM_STATUS_CMD_UNSUCCESSFUL;
  340. outb((u8) cmd_status, PCAT_APM_STATUS_PORT);
  341. /* generate SMM call */
  342. outb(ESM_APM_CMD, PCAT_APM_CONTROL_PORT);
  343. spin_unlock_irqrestore(&rtc_lock, flags);
  344. /* wait a few to see if it executed */
  345. num_ticks = TIMEOUT_USEC_SHORT_SEMA_BLOCKING;
  346. while ((cmd_status = inb(PCAT_APM_STATUS_PORT))
  347. == ESM_STATUS_CMD_UNSUCCESSFUL) {
  348. num_ticks--;
  349. if (num_ticks == EXPIRED_TIMER)
  350. return -ETIME;
  351. }
  352. break;
  353. case HC_SMITYPE_TYPE2:
  354. case HC_SMITYPE_TYPE3:
  355. spin_lock_irqsave(&rtc_lock, flags);
  356. /* write SMI data buffer physical address */
  357. data = (u8 *)&smi_data_buf_phys_addr;
  358. for (index = PE1400_CMOS_CMD_STRUCT_PTR;
  359. index < (PE1400_CMOS_CMD_STRUCT_PTR + 4);
  360. index++, data++) {
  361. outb(index, (CMOS_BASE_PORT + CMOS_PAGE1_INDEX_PORT));
  362. outb(*data, (CMOS_BASE_PORT + CMOS_PAGE1_DATA_PORT));
  363. }
  364. /* generate SMM call */
  365. if (host_control_smi_type == HC_SMITYPE_TYPE3)
  366. outb(ESM_APM_CMD, PCAT_APM_CONTROL_PORT);
  367. else
  368. outb(ESM_APM_CMD, PE1400_APM_CONTROL_PORT);
  369. /* restore RTC index pointer since it was written to above */
  370. CMOS_READ(RTC_REG_C);
  371. spin_unlock_irqrestore(&rtc_lock, flags);
  372. /* read control port back to serialize write */
  373. cmd_status = inb(PE1400_APM_CONTROL_PORT);
  374. /* wait a few to see if it executed */
  375. num_ticks = TIMEOUT_USEC_SHORT_SEMA_BLOCKING;
  376. while (apm_cmd->status == ESM_STATUS_CMD_UNSUCCESSFUL) {
  377. num_ticks--;
  378. if (num_ticks == EXPIRED_TIMER)
  379. return -ETIME;
  380. }
  381. break;
  382. default:
  383. dev_dbg(&dcdbas_pdev->dev, "%s: invalid SMI type %u\n",
  384. __func__, host_control_smi_type);
  385. return -ENOSYS;
  386. }
  387. return 0;
  388. }
  389. /**
  390. * dcdbas_host_control: initiate host control
  391. *
  392. * This function is called by the driver after the system has
  393. * finished shutting down if the user application specified a
  394. * host control action to perform on shutdown. It is safe to
  395. * use smi_data_buf at this point because the system has finished
  396. * shutting down and no userspace apps are running.
  397. */
  398. static void dcdbas_host_control(void)
  399. {
  400. struct apm_cmd *apm_cmd;
  401. u8 action;
  402. if (host_control_action == HC_ACTION_NONE)
  403. return;
  404. action = host_control_action;
  405. host_control_action = HC_ACTION_NONE;
  406. if (!smi_data_buf) {
  407. dev_dbg(&dcdbas_pdev->dev, "%s: no SMI buffer\n", __func__);
  408. return;
  409. }
  410. if (smi_data_buf_size < sizeof(struct apm_cmd)) {
  411. dev_dbg(&dcdbas_pdev->dev, "%s: SMI buffer too small\n",
  412. __func__);
  413. return;
  414. }
  415. apm_cmd = (struct apm_cmd *)smi_data_buf;
  416. /* power off takes precedence */
  417. if (action & HC_ACTION_HOST_CONTROL_POWEROFF) {
  418. apm_cmd->command = ESM_APM_POWER_CYCLE;
  419. apm_cmd->reserved = 0;
  420. *((s16 *)&apm_cmd->parameters.shortreq.parm[0]) = (s16) 0;
  421. host_control_smi();
  422. } else if (action & HC_ACTION_HOST_CONTROL_POWERCYCLE) {
  423. apm_cmd->command = ESM_APM_POWER_CYCLE;
  424. apm_cmd->reserved = 0;
  425. *((s16 *)&apm_cmd->parameters.shortreq.parm[0]) = (s16) 20;
  426. host_control_smi();
  427. }
  428. }
  429. /* WSMT */
  430. static u8 checksum(u8 *buffer, u8 length)
  431. {
  432. u8 sum = 0;
  433. u8 *end = buffer + length;
  434. while (buffer < end)
  435. sum += *buffer++;
  436. return sum;
  437. }
  438. static inline struct smm_eps_table *check_eps_table(u8 *addr)
  439. {
  440. struct smm_eps_table *eps = (struct smm_eps_table *)addr;
  441. if (strncmp(eps->smm_comm_buff_anchor, SMM_EPS_SIG, 4) != 0)
  442. return NULL;
  443. if (checksum(addr, eps->length) != 0)
  444. return NULL;
  445. return eps;
  446. }
  447. static int dcdbas_check_wsmt(void)
  448. {
  449. struct acpi_table_wsmt *wsmt = NULL;
  450. struct smm_eps_table *eps = NULL;
  451. u64 remap_size;
  452. u8 *addr;
  453. acpi_get_table(ACPI_SIG_WSMT, 0, (struct acpi_table_header **)&wsmt);
  454. if (!wsmt)
  455. return 0;
  456. /* Check if WSMT ACPI table shows that protection is enabled */
  457. if (!(wsmt->protection_flags & ACPI_WSMT_FIXED_COMM_BUFFERS) ||
  458. !(wsmt->protection_flags & ACPI_WSMT_COMM_BUFFER_NESTED_PTR_PROTECTION))
  459. return 0;
  460. /* Scan for EPS (entry point structure) */
  461. for (addr = (u8 *)__va(0xf0000);
  462. addr < (u8 *)__va(0x100000 - sizeof(struct smm_eps_table));
  463. addr += 16) {
  464. eps = check_eps_table(addr);
  465. if (eps)
  466. break;
  467. }
  468. if (!eps) {
  469. dev_dbg(&dcdbas_pdev->dev, "found WSMT, but no EPS found\n");
  470. return -ENODEV;
  471. }
  472. /*
  473. * Get physical address of buffer and map to virtual address.
  474. * Table gives size in 4K pages, regardless of actual system page size.
  475. */
  476. if (upper_32_bits(eps->smm_comm_buff_addr + 8)) {
  477. dev_warn(&dcdbas_pdev->dev, "found WSMT, but EPS buffer address is above 4GB\n");
  478. return -EINVAL;
  479. }
  480. /*
  481. * Limit remap size to MAX_SMI_DATA_BUF_SIZE + 8 (since the first 8
  482. * bytes are used for a semaphore, not the data buffer itself).
  483. */
  484. remap_size = eps->num_of_4k_pages * PAGE_SIZE;
  485. if (remap_size > MAX_SMI_DATA_BUF_SIZE + 8)
  486. remap_size = MAX_SMI_DATA_BUF_SIZE + 8;
  487. eps_buffer = memremap(eps->smm_comm_buff_addr, remap_size, MEMREMAP_WB);
  488. if (!eps_buffer) {
  489. dev_warn(&dcdbas_pdev->dev, "found WSMT, but failed to map EPS buffer\n");
  490. return -ENOMEM;
  491. }
  492. /* First 8 bytes is for a semaphore, not part of the smi_data_buf */
  493. smi_data_buf_phys_addr = eps->smm_comm_buff_addr + 8;
  494. smi_data_buf = eps_buffer + 8;
  495. smi_data_buf_size = remap_size - 8;
  496. max_smi_data_buf_size = smi_data_buf_size;
  497. wsmt_enabled = true;
  498. dev_info(&dcdbas_pdev->dev,
  499. "WSMT found, using firmware-provided SMI buffer.\n");
  500. return 1;
  501. }
  502. /**
  503. * dcdbas_reboot_notify: handle reboot notification for host control
  504. */
  505. static int dcdbas_reboot_notify(struct notifier_block *nb, unsigned long code,
  506. void *unused)
  507. {
  508. switch (code) {
  509. case SYS_DOWN:
  510. case SYS_HALT:
  511. case SYS_POWER_OFF:
  512. if (host_control_on_shutdown) {
  513. /* firmware is going to perform host control action */
  514. printk(KERN_WARNING "Please wait for shutdown "
  515. "action to complete...\n");
  516. dcdbas_host_control();
  517. }
  518. break;
  519. }
  520. return NOTIFY_DONE;
  521. }
  522. static struct notifier_block dcdbas_reboot_nb = {
  523. .notifier_call = dcdbas_reboot_notify,
  524. .next = NULL,
  525. .priority = INT_MIN
  526. };
  527. static DCDBAS_BIN_ATTR_RW(smi_data);
  528. static struct bin_attribute *dcdbas_bin_attrs[] = {
  529. &bin_attr_smi_data,
  530. NULL
  531. };
  532. static DCDBAS_DEV_ATTR_RW(smi_data_buf_size);
  533. static DCDBAS_DEV_ATTR_RO(smi_data_buf_phys_addr);
  534. static DCDBAS_DEV_ATTR_WO(smi_request);
  535. static DCDBAS_DEV_ATTR_RW(host_control_action);
  536. static DCDBAS_DEV_ATTR_RW(host_control_smi_type);
  537. static DCDBAS_DEV_ATTR_RW(host_control_on_shutdown);
  538. static struct attribute *dcdbas_dev_attrs[] = {
  539. &dev_attr_smi_data_buf_size.attr,
  540. &dev_attr_smi_data_buf_phys_addr.attr,
  541. &dev_attr_smi_request.attr,
  542. &dev_attr_host_control_action.attr,
  543. &dev_attr_host_control_smi_type.attr,
  544. &dev_attr_host_control_on_shutdown.attr,
  545. NULL
  546. };
  547. static const struct attribute_group dcdbas_attr_group = {
  548. .attrs = dcdbas_dev_attrs,
  549. .bin_attrs = dcdbas_bin_attrs,
  550. };
  551. static int dcdbas_probe(struct platform_device *dev)
  552. {
  553. int error;
  554. host_control_action = HC_ACTION_NONE;
  555. host_control_smi_type = HC_SMITYPE_NONE;
  556. dcdbas_pdev = dev;
  557. /* Check if ACPI WSMT table specifies protected SMI buffer address */
  558. error = dcdbas_check_wsmt();
  559. if (error < 0)
  560. return error;
  561. /*
  562. * BIOS SMI calls require buffer addresses be in 32-bit address space.
  563. * This is done by setting the DMA mask below.
  564. */
  565. error = dma_set_coherent_mask(&dcdbas_pdev->dev, DMA_BIT_MASK(32));
  566. if (error)
  567. return error;
  568. error = sysfs_create_group(&dev->dev.kobj, &dcdbas_attr_group);
  569. if (error)
  570. return error;
  571. register_reboot_notifier(&dcdbas_reboot_nb);
  572. dev_info(&dev->dev, "%s (version %s)\n",
  573. DRIVER_DESCRIPTION, DRIVER_VERSION);
  574. return 0;
  575. }
  576. static int dcdbas_remove(struct platform_device *dev)
  577. {
  578. unregister_reboot_notifier(&dcdbas_reboot_nb);
  579. sysfs_remove_group(&dev->dev.kobj, &dcdbas_attr_group);
  580. return 0;
  581. }
  582. static struct platform_driver dcdbas_driver = {
  583. .driver = {
  584. .name = DRIVER_NAME,
  585. },
  586. .probe = dcdbas_probe,
  587. .remove = dcdbas_remove,
  588. };
  589. static const struct platform_device_info dcdbas_dev_info __initconst = {
  590. .name = DRIVER_NAME,
  591. .id = -1,
  592. .dma_mask = DMA_BIT_MASK(32),
  593. };
  594. static struct platform_device *dcdbas_pdev_reg;
  595. /**
  596. * dcdbas_init: initialize driver
  597. */
  598. static int __init dcdbas_init(void)
  599. {
  600. int error;
  601. error = platform_driver_register(&dcdbas_driver);
  602. if (error)
  603. return error;
  604. dcdbas_pdev_reg = platform_device_register_full(&dcdbas_dev_info);
  605. if (IS_ERR(dcdbas_pdev_reg)) {
  606. error = PTR_ERR(dcdbas_pdev_reg);
  607. goto err_unregister_driver;
  608. }
  609. return 0;
  610. err_unregister_driver:
  611. platform_driver_unregister(&dcdbas_driver);
  612. return error;
  613. }
  614. /**
  615. * dcdbas_exit: perform driver cleanup
  616. */
  617. static void __exit dcdbas_exit(void)
  618. {
  619. /*
  620. * make sure functions that use dcdbas_pdev are called
  621. * before platform_device_unregister
  622. */
  623. unregister_reboot_notifier(&dcdbas_reboot_nb);
  624. /*
  625. * We have to free the buffer here instead of dcdbas_remove
  626. * because only in module exit function we can be sure that
  627. * all sysfs attributes belonging to this module have been
  628. * released.
  629. */
  630. if (dcdbas_pdev)
  631. smi_data_buf_free();
  632. if (eps_buffer)
  633. memunmap(eps_buffer);
  634. platform_device_unregister(dcdbas_pdev_reg);
  635. platform_driver_unregister(&dcdbas_driver);
  636. }
  637. subsys_initcall_sync(dcdbas_init);
  638. module_exit(dcdbas_exit);
  639. MODULE_DESCRIPTION(DRIVER_DESCRIPTION " (version " DRIVER_VERSION ")");
  640. MODULE_VERSION(DRIVER_VERSION);
  641. MODULE_AUTHOR("Dell Inc.");
  642. MODULE_LICENSE("GPL");
  643. /* Any System or BIOS claiming to be by Dell */
  644. MODULE_ALIAS("dmi:*:[bs]vnD[Ee][Ll][Ll]*:*");