dcdbas.c 19 KB

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