blob: 25918f7dfd0fe73884ff86101ed90c04346e00cb [file] [log] [blame]
Doug Warzecha90563ec2005-09-06 15:17:15 -07001/*
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 *
Doug Warzechab95936c2006-10-19 23:29:09 -070011 * Copyright (C) 1995-2006 Dell Inc.
Doug Warzecha90563ec2005-09-06 15:17:15 -070012 *
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
Russell Kingd052d1b2005-10-29 19:07:23 +010023#include <linux/platform_device.h>
Doug Warzecha90563ec2005-09-06 15:17:15 -070024#include <linux/dma-mapping.h>
25#include <linux/errno.h>
26#include <linux/init.h>
27#include <linux/kernel.h>
28#include <linux/mc146818rtc.h>
29#include <linux/module.h>
30#include <linux/reboot.h>
31#include <linux/sched.h>
32#include <linux/smp.h>
33#include <linux/spinlock.h>
34#include <linux/string.h>
35#include <linux/types.h>
Arjan van de Ven8ed965d2006-03-23 03:00:21 -080036#include <linux/mutex.h>
Doug Warzecha90563ec2005-09-06 15:17:15 -070037#include <asm/io.h>
Doug Warzecha90563ec2005-09-06 15:17:15 -070038
39#include "dcdbas.h"
40
41#define DRIVER_NAME "dcdbas"
Doug Warzechab95936c2006-10-19 23:29:09 -070042#define DRIVER_VERSION "5.6.0-3.2"
Doug Warzecha90563ec2005-09-06 15:17:15 -070043#define DRIVER_DESCRIPTION "Dell Systems Management Base Driver"
44
45static struct platform_device *dcdbas_pdev;
46
47static u8 *smi_data_buf;
48static dma_addr_t smi_data_buf_handle;
49static unsigned long smi_data_buf_size;
50static u32 smi_data_buf_phys_addr;
Arjan van de Ven8ed965d2006-03-23 03:00:21 -080051static DEFINE_MUTEX(smi_data_lock);
Doug Warzecha90563ec2005-09-06 15:17:15 -070052
53static unsigned int host_control_action;
54static unsigned int host_control_smi_type;
55static unsigned int host_control_on_shutdown;
56
57/**
58 * smi_data_buf_free: free SMI data buffer
59 */
60static void smi_data_buf_free(void)
61{
62 if (!smi_data_buf)
63 return;
64
65 dev_dbg(&dcdbas_pdev->dev, "%s: phys: %x size: %lu\n",
Harvey Harrisoneecd5852008-04-29 00:59:19 -070066 __func__, smi_data_buf_phys_addr, smi_data_buf_size);
Doug Warzecha90563ec2005-09-06 15:17:15 -070067
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 */
79static 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",
Harvey Harrisoneecd5852008-04-29 00:59:19 -070095 __func__, size);
Doug Warzecha90563ec2005-09-06 15:17:15 -070096 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",
Harvey Harrisoneecd5852008-04-29 00:59:19 -0700113 __func__, smi_data_buf_phys_addr, smi_data_buf_size);
Doug Warzecha90563ec2005-09-06 15:17:15 -0700114
115 return 0;
116}
117
118static 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
125static 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
132static 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 */
Arjan van de Ven8ed965d2006-03-23 03:00:21 -0800142 mutex_lock(&smi_data_lock);
Doug Warzecha90563ec2005-09-06 15:17:15 -0700143 ret = smi_data_buf_realloc(buf_size);
Arjan van de Ven8ed965d2006-03-23 03:00:21 -0800144 mutex_unlock(&smi_data_lock);
Doug Warzecha90563ec2005-09-06 15:17:15 -0700145 if (ret)
146 return ret;
147
148 return count;
149}
150
Zhang Rui91a69022007-06-09 13:57:22 +0800151static ssize_t smi_data_read(struct kobject *kobj,
152 struct bin_attribute *bin_attr,
153 char *buf, loff_t pos, size_t count)
Doug Warzecha90563ec2005-09-06 15:17:15 -0700154{
155 size_t max_read;
156 ssize_t ret;
157
Arjan van de Ven8ed965d2006-03-23 03:00:21 -0800158 mutex_lock(&smi_data_lock);
Doug Warzecha90563ec2005-09-06 15:17:15 -0700159
160 if (pos >= smi_data_buf_size) {
161 ret = 0;
162 goto out;
163 }
164
165 max_read = smi_data_buf_size - pos;
166 ret = min(max_read, count);
167 memcpy(buf, smi_data_buf + pos, ret);
168out:
Arjan van de Ven8ed965d2006-03-23 03:00:21 -0800169 mutex_unlock(&smi_data_lock);
Doug Warzecha90563ec2005-09-06 15:17:15 -0700170 return ret;
171}
172
Zhang Rui91a69022007-06-09 13:57:22 +0800173static ssize_t smi_data_write(struct kobject *kobj,
174 struct bin_attribute *bin_attr,
175 char *buf, loff_t pos, size_t count)
Doug Warzecha90563ec2005-09-06 15:17:15 -0700176{
177 ssize_t ret;
178
Doug Warzechab95936c2006-10-19 23:29:09 -0700179 if ((pos + count) > MAX_SMI_DATA_BUF_SIZE)
180 return -EINVAL;
181
Arjan van de Ven8ed965d2006-03-23 03:00:21 -0800182 mutex_lock(&smi_data_lock);
Doug Warzecha90563ec2005-09-06 15:17:15 -0700183
184 ret = smi_data_buf_realloc(pos + count);
185 if (ret)
186 goto out;
187
188 memcpy(smi_data_buf + pos, buf, count);
189 ret = count;
190out:
Arjan van de Ven8ed965d2006-03-23 03:00:21 -0800191 mutex_unlock(&smi_data_lock);
Doug Warzecha90563ec2005-09-06 15:17:15 -0700192 return ret;
193}
194
195static ssize_t host_control_action_show(struct device *dev,
196 struct device_attribute *attr,
197 char *buf)
198{
199 return sprintf(buf, "%u\n", host_control_action);
200}
201
202static ssize_t host_control_action_store(struct device *dev,
203 struct device_attribute *attr,
204 const char *buf, size_t count)
205{
206 ssize_t ret;
207
208 /* make sure buffer is available for host control command */
Arjan van de Ven8ed965d2006-03-23 03:00:21 -0800209 mutex_lock(&smi_data_lock);
Doug Warzecha90563ec2005-09-06 15:17:15 -0700210 ret = smi_data_buf_realloc(sizeof(struct apm_cmd));
Arjan van de Ven8ed965d2006-03-23 03:00:21 -0800211 mutex_unlock(&smi_data_lock);
Doug Warzecha90563ec2005-09-06 15:17:15 -0700212 if (ret)
213 return ret;
214
215 host_control_action = simple_strtoul(buf, NULL, 10);
216 return count;
217}
218
219static ssize_t host_control_smi_type_show(struct device *dev,
220 struct device_attribute *attr,
221 char *buf)
222{
223 return sprintf(buf, "%u\n", host_control_smi_type);
224}
225
226static ssize_t host_control_smi_type_store(struct device *dev,
227 struct device_attribute *attr,
228 const char *buf, size_t count)
229{
230 host_control_smi_type = simple_strtoul(buf, NULL, 10);
231 return count;
232}
233
234static ssize_t host_control_on_shutdown_show(struct device *dev,
235 struct device_attribute *attr,
236 char *buf)
237{
238 return sprintf(buf, "%u\n", host_control_on_shutdown);
239}
240
241static ssize_t host_control_on_shutdown_store(struct device *dev,
242 struct device_attribute *attr,
243 const char *buf, size_t count)
244{
245 host_control_on_shutdown = simple_strtoul(buf, NULL, 10);
246 return count;
247}
248
249/**
250 * smi_request: generate SMI request
251 *
252 * Called with smi_data_lock.
253 */
254static int smi_request(struct smi_cmd *smi_cmd)
255{
256 cpumask_t old_mask;
257 int ret = 0;
258
259 if (smi_cmd->magic != SMI_CMD_MAGIC) {
260 dev_info(&dcdbas_pdev->dev, "%s: invalid magic value\n",
Harvey Harrisoneecd5852008-04-29 00:59:19 -0700261 __func__);
Doug Warzecha90563ec2005-09-06 15:17:15 -0700262 return -EBADR;
263 }
264
265 /* SMI requires CPU 0 */
266 old_mask = current->cpus_allowed;
Mike Travisf70316d2008-04-04 18:11:06 -0700267 set_cpus_allowed_ptr(current, &cpumask_of_cpu(0));
Doug Warzecha90563ec2005-09-06 15:17:15 -0700268 if (smp_processor_id() != 0) {
269 dev_dbg(&dcdbas_pdev->dev, "%s: failed to get CPU 0\n",
Harvey Harrisoneecd5852008-04-29 00:59:19 -0700270 __func__);
Doug Warzecha90563ec2005-09-06 15:17:15 -0700271 ret = -EBUSY;
272 goto out;
273 }
274
275 /* generate SMI */
276 asm volatile (
277 "outb %b0,%w1"
278 : /* no output args */
279 : "a" (smi_cmd->command_code),
280 "d" (smi_cmd->command_address),
281 "b" (smi_cmd->ebx),
282 "c" (smi_cmd->ecx)
283 : "memory"
284 );
285
286out:
Mike Travisf70316d2008-04-04 18:11:06 -0700287 set_cpus_allowed_ptr(current, &old_mask);
Doug Warzecha90563ec2005-09-06 15:17:15 -0700288 return ret;
289}
290
291/**
292 * smi_request_store:
293 *
294 * The valid values are:
295 * 0: zero SMI data buffer
296 * 1: generate calling interface SMI
297 * 2: generate raw SMI
298 *
299 * User application writes smi_cmd to smi_data before telling driver
300 * to generate SMI.
301 */
302static ssize_t smi_request_store(struct device *dev,
303 struct device_attribute *attr,
304 const char *buf, size_t count)
305{
306 struct smi_cmd *smi_cmd;
307 unsigned long val = simple_strtoul(buf, NULL, 10);
308 ssize_t ret;
309
Arjan van de Ven8ed965d2006-03-23 03:00:21 -0800310 mutex_lock(&smi_data_lock);
Doug Warzecha90563ec2005-09-06 15:17:15 -0700311
312 if (smi_data_buf_size < sizeof(struct smi_cmd)) {
313 ret = -ENODEV;
314 goto out;
315 }
316 smi_cmd = (struct smi_cmd *)smi_data_buf;
317
318 switch (val) {
319 case 2:
320 /* Raw SMI */
321 ret = smi_request(smi_cmd);
322 if (!ret)
323 ret = count;
324 break;
325 case 1:
326 /* Calling Interface SMI */
327 smi_cmd->ebx = (u32) virt_to_phys(smi_cmd->command_buffer);
328 ret = smi_request(smi_cmd);
329 if (!ret)
330 ret = count;
331 break;
332 case 0:
333 memset(smi_data_buf, 0, smi_data_buf_size);
334 ret = count;
335 break;
336 default:
337 ret = -EINVAL;
338 break;
339 }
340
341out:
Arjan van de Ven8ed965d2006-03-23 03:00:21 -0800342 mutex_unlock(&smi_data_lock);
Doug Warzecha90563ec2005-09-06 15:17:15 -0700343 return ret;
344}
345
346/**
347 * host_control_smi: generate host control SMI
348 *
349 * Caller must set up the host control command in smi_data_buf.
350 */
351static int host_control_smi(void)
352{
353 struct apm_cmd *apm_cmd;
354 u8 *data;
355 unsigned long flags;
356 u32 num_ticks;
357 s8 cmd_status;
358 u8 index;
359
360 apm_cmd = (struct apm_cmd *)smi_data_buf;
361 apm_cmd->status = ESM_STATUS_CMD_UNSUCCESSFUL;
362
363 switch (host_control_smi_type) {
364 case HC_SMITYPE_TYPE1:
365 spin_lock_irqsave(&rtc_lock, flags);
366 /* write SMI data buffer physical address */
367 data = (u8 *)&smi_data_buf_phys_addr;
368 for (index = PE1300_CMOS_CMD_STRUCT_PTR;
369 index < (PE1300_CMOS_CMD_STRUCT_PTR + 4);
370 index++, data++) {
371 outb(index,
372 (CMOS_BASE_PORT + CMOS_PAGE2_INDEX_PORT_PIIX4));
373 outb(*data,
374 (CMOS_BASE_PORT + CMOS_PAGE2_DATA_PORT_PIIX4));
375 }
376
377 /* first set status to -1 as called by spec */
378 cmd_status = ESM_STATUS_CMD_UNSUCCESSFUL;
379 outb((u8) cmd_status, PCAT_APM_STATUS_PORT);
380
381 /* generate SMM call */
382 outb(ESM_APM_CMD, PCAT_APM_CONTROL_PORT);
383 spin_unlock_irqrestore(&rtc_lock, flags);
384
385 /* wait a few to see if it executed */
386 num_ticks = TIMEOUT_USEC_SHORT_SEMA_BLOCKING;
387 while ((cmd_status = inb(PCAT_APM_STATUS_PORT))
388 == ESM_STATUS_CMD_UNSUCCESSFUL) {
389 num_ticks--;
390 if (num_ticks == EXPIRED_TIMER)
391 return -ETIME;
392 }
393 break;
394
395 case HC_SMITYPE_TYPE2:
396 case HC_SMITYPE_TYPE3:
397 spin_lock_irqsave(&rtc_lock, flags);
398 /* write SMI data buffer physical address */
399 data = (u8 *)&smi_data_buf_phys_addr;
400 for (index = PE1400_CMOS_CMD_STRUCT_PTR;
401 index < (PE1400_CMOS_CMD_STRUCT_PTR + 4);
402 index++, data++) {
403 outb(index, (CMOS_BASE_PORT + CMOS_PAGE1_INDEX_PORT));
404 outb(*data, (CMOS_BASE_PORT + CMOS_PAGE1_DATA_PORT));
405 }
406
407 /* generate SMM call */
408 if (host_control_smi_type == HC_SMITYPE_TYPE3)
409 outb(ESM_APM_CMD, PCAT_APM_CONTROL_PORT);
410 else
411 outb(ESM_APM_CMD, PE1400_APM_CONTROL_PORT);
412
413 /* restore RTC index pointer since it was written to above */
414 CMOS_READ(RTC_REG_C);
415 spin_unlock_irqrestore(&rtc_lock, flags);
416
417 /* read control port back to serialize write */
418 cmd_status = inb(PE1400_APM_CONTROL_PORT);
419
420 /* wait a few to see if it executed */
421 num_ticks = TIMEOUT_USEC_SHORT_SEMA_BLOCKING;
422 while (apm_cmd->status == ESM_STATUS_CMD_UNSUCCESSFUL) {
423 num_ticks--;
424 if (num_ticks == EXPIRED_TIMER)
425 return -ETIME;
426 }
427 break;
428
429 default:
430 dev_dbg(&dcdbas_pdev->dev, "%s: invalid SMI type %u\n",
Harvey Harrisoneecd5852008-04-29 00:59:19 -0700431 __func__, host_control_smi_type);
Doug Warzecha90563ec2005-09-06 15:17:15 -0700432 return -ENOSYS;
433 }
434
435 return 0;
436}
437
438/**
439 * dcdbas_host_control: initiate host control
440 *
441 * This function is called by the driver after the system has
442 * finished shutting down if the user application specified a
443 * host control action to perform on shutdown. It is safe to
444 * use smi_data_buf at this point because the system has finished
445 * shutting down and no userspace apps are running.
446 */
447static void dcdbas_host_control(void)
448{
449 struct apm_cmd *apm_cmd;
450 u8 action;
451
452 if (host_control_action == HC_ACTION_NONE)
453 return;
454
455 action = host_control_action;
456 host_control_action = HC_ACTION_NONE;
457
458 if (!smi_data_buf) {
Harvey Harrisoneecd5852008-04-29 00:59:19 -0700459 dev_dbg(&dcdbas_pdev->dev, "%s: no SMI buffer\n", __func__);
Doug Warzecha90563ec2005-09-06 15:17:15 -0700460 return;
461 }
462
463 if (smi_data_buf_size < sizeof(struct apm_cmd)) {
464 dev_dbg(&dcdbas_pdev->dev, "%s: SMI buffer too small\n",
Harvey Harrisoneecd5852008-04-29 00:59:19 -0700465 __func__);
Doug Warzecha90563ec2005-09-06 15:17:15 -0700466 return;
467 }
468
469 apm_cmd = (struct apm_cmd *)smi_data_buf;
470
471 /* power off takes precedence */
472 if (action & HC_ACTION_HOST_CONTROL_POWEROFF) {
473 apm_cmd->command = ESM_APM_POWER_CYCLE;
474 apm_cmd->reserved = 0;
475 *((s16 *)&apm_cmd->parameters.shortreq.parm[0]) = (s16) 0;
476 host_control_smi();
477 } else if (action & HC_ACTION_HOST_CONTROL_POWERCYCLE) {
478 apm_cmd->command = ESM_APM_POWER_CYCLE;
479 apm_cmd->reserved = 0;
480 *((s16 *)&apm_cmd->parameters.shortreq.parm[0]) = (s16) 20;
481 host_control_smi();
482 }
483}
484
485/**
486 * dcdbas_reboot_notify: handle reboot notification for host control
487 */
488static int dcdbas_reboot_notify(struct notifier_block *nb, unsigned long code,
489 void *unused)
490{
Doug Warzecha90563ec2005-09-06 15:17:15 -0700491 switch (code) {
492 case SYS_DOWN:
493 case SYS_HALT:
494 case SYS_POWER_OFF:
495 if (host_control_on_shutdown) {
496 /* firmware is going to perform host control action */
Alan Sterne041c682006-03-27 01:16:30 -0800497 printk(KERN_WARNING "Please wait for shutdown "
498 "action to complete...\n");
499 dcdbas_host_control();
Doug Warzecha90563ec2005-09-06 15:17:15 -0700500 }
501 break;
502 }
503
504 return NOTIFY_DONE;
505}
506
507static struct notifier_block dcdbas_reboot_nb = {
508 .notifier_call = dcdbas_reboot_notify,
509 .next = NULL,
Alan Sterne041c682006-03-27 01:16:30 -0800510 .priority = INT_MIN
Doug Warzecha90563ec2005-09-06 15:17:15 -0700511};
512
513static DCDBAS_BIN_ATTR_RW(smi_data);
514
515static struct bin_attribute *dcdbas_bin_attrs[] = {
516 &bin_attr_smi_data,
517 NULL
518};
519
520static DCDBAS_DEV_ATTR_RW(smi_data_buf_size);
521static DCDBAS_DEV_ATTR_RO(smi_data_buf_phys_addr);
522static DCDBAS_DEV_ATTR_WO(smi_request);
523static DCDBAS_DEV_ATTR_RW(host_control_action);
524static DCDBAS_DEV_ATTR_RW(host_control_smi_type);
525static DCDBAS_DEV_ATTR_RW(host_control_on_shutdown);
526
Dmitry Torokhova7f3ea72006-03-22 00:07:56 -0800527static struct attribute *dcdbas_dev_attrs[] = {
528 &dev_attr_smi_data_buf_size.attr,
529 &dev_attr_smi_data_buf_phys_addr.attr,
530 &dev_attr_smi_request.attr,
531 &dev_attr_host_control_action.attr,
532 &dev_attr_host_control_smi_type.attr,
533 &dev_attr_host_control_on_shutdown.attr,
Doug Warzecha90563ec2005-09-06 15:17:15 -0700534 NULL
535};
536
Dmitry Torokhova7f3ea72006-03-22 00:07:56 -0800537static struct attribute_group dcdbas_attr_group = {
538 .attrs = dcdbas_dev_attrs,
539};
540
541static int __devinit dcdbas_probe(struct platform_device *dev)
Doug Warzecha90563ec2005-09-06 15:17:15 -0700542{
Dmitry Torokhova7f3ea72006-03-22 00:07:56 -0800543 int i, error;
Doug Warzecha90563ec2005-09-06 15:17:15 -0700544
545 host_control_action = HC_ACTION_NONE;
546 host_control_smi_type = HC_SMITYPE_NONE;
547
Doug Warzecha90563ec2005-09-06 15:17:15 -0700548 /*
549 * BIOS SMI calls require buffer addresses be in 32-bit address space.
550 * This is done by setting the DMA mask below.
551 */
552 dcdbas_pdev->dev.coherent_dma_mask = DMA_32BIT_MASK;
553 dcdbas_pdev->dev.dma_mask = &dcdbas_pdev->dev.coherent_dma_mask;
554
Dmitry Torokhova7f3ea72006-03-22 00:07:56 -0800555 error = sysfs_create_group(&dev->dev.kobj, &dcdbas_attr_group);
556 if (error)
557 return error;
558
559 for (i = 0; dcdbas_bin_attrs[i]; i++) {
560 error = sysfs_create_bin_file(&dev->dev.kobj,
561 dcdbas_bin_attrs[i]);
562 if (error) {
563 while (--i >= 0)
564 sysfs_remove_bin_file(&dev->dev.kobj,
565 dcdbas_bin_attrs[i]);
Jeff Garzik0968cf512006-10-10 02:58:14 -0400566 sysfs_remove_group(&dev->dev.kobj, &dcdbas_attr_group);
Dmitry Torokhova7f3ea72006-03-22 00:07:56 -0800567 return error;
568 }
569 }
570
Doug Warzecha90563ec2005-09-06 15:17:15 -0700571 register_reboot_notifier(&dcdbas_reboot_nb);
572
Dmitry Torokhova7f3ea72006-03-22 00:07:56 -0800573 dev_info(&dev->dev, "%s (version %s)\n",
Doug Warzecha90563ec2005-09-06 15:17:15 -0700574 DRIVER_DESCRIPTION, DRIVER_VERSION);
575
576 return 0;
577}
578
Dmitry Torokhova7f3ea72006-03-22 00:07:56 -0800579static int __devexit dcdbas_remove(struct platform_device *dev)
580{
581 int i;
582
583 unregister_reboot_notifier(&dcdbas_reboot_nb);
584 for (i = 0; dcdbas_bin_attrs[i]; i++)
585 sysfs_remove_bin_file(&dev->dev.kobj, dcdbas_bin_attrs[i]);
586 sysfs_remove_group(&dev->dev.kobj, &dcdbas_attr_group);
587
588 return 0;
589}
590
591static struct platform_driver dcdbas_driver = {
592 .driver = {
593 .name = DRIVER_NAME,
594 .owner = THIS_MODULE,
595 },
596 .probe = dcdbas_probe,
597 .remove = __devexit_p(dcdbas_remove),
598};
599
600/**
601 * dcdbas_init: initialize driver
602 */
603static int __init dcdbas_init(void)
604{
605 int error;
606
607 error = platform_driver_register(&dcdbas_driver);
608 if (error)
609 return error;
610
611 dcdbas_pdev = platform_device_alloc(DRIVER_NAME, -1);
612 if (!dcdbas_pdev) {
613 error = -ENOMEM;
614 goto err_unregister_driver;
615 }
616
617 error = platform_device_add(dcdbas_pdev);
618 if (error)
619 goto err_free_device;
620
621 return 0;
622
623 err_free_device:
624 platform_device_put(dcdbas_pdev);
625 err_unregister_driver:
626 platform_driver_unregister(&dcdbas_driver);
627 return error;
628}
629
Doug Warzecha90563ec2005-09-06 15:17:15 -0700630/**
631 * dcdbas_exit: perform driver cleanup
632 */
633static void __exit dcdbas_exit(void)
634{
Doug Warzecha435a80f2006-03-09 17:33:35 -0800635 /*
636 * make sure functions that use dcdbas_pdev are called
637 * before platform_device_unregister
638 */
Doug Warzecha90563ec2005-09-06 15:17:15 -0700639 unregister_reboot_notifier(&dcdbas_reboot_nb);
640 smi_data_buf_free();
Doug Warzecha435a80f2006-03-09 17:33:35 -0800641 platform_device_unregister(dcdbas_pdev);
Dmitry Torokhova7f3ea72006-03-22 00:07:56 -0800642 platform_driver_unregister(&dcdbas_driver);
643
644 /*
645 * We have to free the buffer here instead of dcdbas_remove
646 * because only in module exit function we can be sure that
647 * all sysfs attributes belonging to this module have been
648 * released.
649 */
650 smi_data_buf_free();
Doug Warzecha90563ec2005-09-06 15:17:15 -0700651}
652
653module_init(dcdbas_init);
654module_exit(dcdbas_exit);
655
656MODULE_DESCRIPTION(DRIVER_DESCRIPTION " (version " DRIVER_VERSION ")");
657MODULE_VERSION(DRIVER_VERSION);
658MODULE_AUTHOR("Dell Inc.");
659MODULE_LICENSE("GPL");
Matt Domsch8f47f0b2008-02-06 01:36:24 -0800660/* Any System or BIOS claiming to be by Dell */
661MODULE_ALIAS("dmi:*:[bs]vnD[Ee][Ll][Ll]*:*");