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