3 * IBM ASM Service Processor Device Driver
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * Copyright (C) IBM Corporation, 2004
21 * Author: Max Asböck <amax@us.ibm.com>
23 * This driver is based on code originally written by Pete Reynolds
29 * The ASM device driver does the following things:
31 * 1) When loaded it sends a message to the service processor,
32 * indicating that an OS is * running. This causes the service processor
33 * to send periodic heartbeats to the OS.
35 * 2) Answers the periodic heartbeats sent by the service processor.
36 * Failure to do so would result in system reboot.
38 * 3) Acts as a pass through for dot commands sent from user applications.
39 * The interface for this is the ibmasmfs file system.
41 * 4) Allows user applications to register for event notification. Events
42 * are sent to the driver through interrupts. They can be read from user
43 * space through the ibmasmfs file system.
45 * 5) Allows user space applications to send heartbeats to the service
46 * processor (aka reverse heartbeats). Again this happens through ibmasmfs.
48 * 6) Handles remote mouse and keyboard event interrupts and makes them
49 * available to user applications through ibmasmfs.
53 #include <linux/pci.h>
54 #include <linux/init.h>
60 static int __init ibmasm_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
63 struct service_processor *sp;
65 sp = kmalloc(sizeof(struct service_processor), GFP_KERNEL);
67 dev_err(&pdev->dev, "Failed to allocate memory\n");
70 memset(sp, 0, sizeof(struct service_processor));
72 pci_set_drvdata(pdev, (void *)sp);
74 sp->number = pdev->bus->number;
75 snprintf(sp->dirname, IBMASM_NAME_SIZE, "%d", sp->number);
76 snprintf(sp->devname, IBMASM_NAME_SIZE, "%s%d", DRIVER_NAME, sp->number);
78 if (ibmasm_event_buffer_init(sp)) {
79 dev_err(sp->dev, "Failed to allocate event buffer\n");
80 goto error_eventbuffer;
83 if (ibmasm_heartbeat_init(sp)) {
84 dev_err(sp->dev, "Failed to allocate heartbeat command\n");
89 sp->base_address = ioremap(pci_resource_start(pdev, 0),
90 pci_resource_len(pdev, 0));
91 if (sp->base_address == 0) {
92 dev_err(sp->dev, "Failed to ioremap pci memory\n");
97 result = ibmasm_init_remote_queue(sp);
99 dev_err(sp->dev, "Failed to initialize remote queue\n");
100 goto error_remote_queue;
103 sp->lock = SPIN_LOCK_UNLOCKED;
104 INIT_LIST_HEAD(&sp->command_queue);
106 result = request_irq(sp->irq, ibmasm_interrupt_handler, SA_SHIRQ, sp->devname, (void*)sp);
108 dev_err(sp->dev, "Failed to register interrupt handler\n");
109 goto error_request_irq;
112 enable_sp_interrupts(sp->base_address);
113 disable_mouse_interrupts(sp);
115 result = ibmasm_send_driver_vpd(sp);
117 dev_err(sp->dev, "Failed to send driver VPD to service processor\n");
118 goto error_send_message;
120 result = ibmasm_send_os_state(sp, SYSTEM_STATE_OS_UP);
122 dev_err(sp->dev, "Failed to send OS state to service processor\n");
123 goto error_send_message;
127 ibmasm_register_uart(sp);
129 dev_printk(KERN_DEBUG, &pdev->dev, "WARNING: This software may not be supported or function\n");
130 dev_printk(KERN_DEBUG, &pdev->dev, "correctly on your IBM server. Please consult the IBM\n");
131 dev_printk(KERN_DEBUG, &pdev->dev, "ServerProven website\n");
132 dev_printk(KERN_DEBUG, &pdev->dev, "http://www.pc.ibm.com/ww/eserver/xseries/serverproven\n");
133 dev_printk(KERN_DEBUG, &pdev->dev, "for information on the specific driver level and support\n");
134 dev_printk(KERN_DEBUG, &pdev->dev, "statement for your IBM server.\n");
139 disable_sp_interrupts(sp->base_address);
140 free_irq(sp->irq, (void *)sp);
142 ibmasm_free_remote_queue(sp);
144 iounmap(sp->base_address);
146 ibmasm_heartbeat_exit(sp);
148 ibmasm_event_buffer_exit(sp);
155 static void __exit ibmasm_remove_one(struct pci_dev *pdev)
157 struct service_processor *sp = (struct service_processor *)pci_get_drvdata(pdev);
159 ibmasm_unregister_uart(sp);
160 ibmasm_send_os_state(sp, SYSTEM_STATE_OS_DOWN);
161 disable_sp_interrupts(sp->base_address);
162 disable_mouse_interrupts(sp);
163 free_irq(sp->irq, (void *)sp);
164 ibmasm_heartbeat_exit(sp);
165 ibmasm_free_remote_queue(sp);
166 iounmap(sp->base_address);
167 ibmasm_event_buffer_exit(sp);
171 static struct pci_device_id ibmasm_pci_table[] =
173 { PCI_DEVICE(VENDORID_IBM, DEVICEID_RSA) },
177 static struct pci_driver ibmasm_driver = {
179 .id_table = ibmasm_pci_table,
180 .probe = ibmasm_init_one,
181 .remove = __devexit_p(ibmasm_remove_one),
184 static void __exit ibmasm_exit (void)
186 ibmasm_unregister_panic_notifier();
187 ibmasmfs_unregister();
188 pci_unregister_driver(&ibmasm_driver);
189 info(DRIVER_DESC " version " DRIVER_VERSION " unloaded");
192 static int __init ibmasm_init(void)
196 result = ibmasmfs_register();
198 err("Failed to register ibmasmfs file system");
201 result = pci_register_driver(&ibmasm_driver);
203 pci_unregister_driver(&ibmasm_driver);
204 ibmasmfs_unregister();
207 ibmasm_register_panic_notifier();
208 info(DRIVER_DESC " version " DRIVER_VERSION " loaded");
212 module_init(ibmasm_init);
213 module_exit(ibmasm_exit);
215 MODULE_AUTHOR(DRIVER_AUTHOR);
216 MODULE_DESCRIPTION(DRIVER_DESC);
217 MODULE_LICENSE("GPL");