blob: 9706cc19134a1bc7b96e812e2717846ded951717 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001
2/*
3 * IBM ASM Service Processor Device Driver
4 *
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.
9 *
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.
14 *
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.
18 *
19 * Copyright (C) IBM Corporation, 2004
20 *
21 * Author: Max Asböck <amax@us.ibm.com>
22 *
23 * This driver is based on code originally written by Pete Reynolds
24 * and others.
25 *
26 */
27
28/*
29 * The ASM device driver does the following things:
30 *
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.
34 *
35 * 2) Answers the periodic heartbeats sent by the service processor.
36 * Failure to do so would result in system reboot.
37 *
38 * 3) Acts as a pass through for dot commands sent from user applications.
39 * The interface for this is the ibmasmfs file system.
40 *
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.
44 *
45 * 5) Allows user space applications to send heartbeats to the service
46 * processor (aka reverse heartbeats). Again this happens through ibmasmfs.
47 *
48 * 6) Handles remote mouse and keyboard event interrupts and makes them
49 * available to user applications through ibmasmfs.
50 *
51 */
52
53#include <linux/pci.h>
54#include <linux/init.h>
55#include "ibmasm.h"
56#include "lowlevel.h"
57#include "remote.h"
58
Max Asbock278d72a2005-06-21 17:16:34 -070059int ibmasm_debug = 0;
60module_param(ibmasm_debug, int , S_IRUGO | S_IWUSR);
61MODULE_PARM_DESC(ibmasm_debug, " Set debug mode on or off");
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64static int __devinit ibmasm_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
65{
Max Asbock278d72a2005-06-21 17:16:34 -070066 int result;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 struct service_processor *sp;
68
Max Asbock278d72a2005-06-21 17:16:34 -070069 if ((result = pci_enable_device(pdev))) {
70 dev_err(&pdev->dev, "Failed to enable PCI device\n");
71 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 }
Max Asbock278d72a2005-06-21 17:16:34 -070073 if ((result = pci_request_regions(pdev, DRIVER_NAME))) {
74 dev_err(&pdev->dev, "Failed to allocate PCI resources\n");
75 goto error_resources;
76 }
77 /* vnc client won't work without bus-mastering */
78 pci_set_master(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80 sp = kmalloc(sizeof(struct service_processor), GFP_KERNEL);
81 if (sp == NULL) {
82 dev_err(&pdev->dev, "Failed to allocate memory\n");
83 result = -ENOMEM;
84 goto error_kmalloc;
85 }
86 memset(sp, 0, sizeof(struct service_processor));
87
Ingo Molnar34af9462006-06-27 02:53:55 -070088 spin_lock_init(&sp->lock);
Max Asbock278d72a2005-06-21 17:16:34 -070089 INIT_LIST_HEAD(&sp->command_queue);
90
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 pci_set_drvdata(pdev, (void *)sp);
92 sp->dev = &pdev->dev;
93 sp->number = pdev->bus->number;
94 snprintf(sp->dirname, IBMASM_NAME_SIZE, "%d", sp->number);
95 snprintf(sp->devname, IBMASM_NAME_SIZE, "%s%d", DRIVER_NAME, sp->number);
96
97 if (ibmasm_event_buffer_init(sp)) {
98 dev_err(sp->dev, "Failed to allocate event buffer\n");
99 goto error_eventbuffer;
100 }
101
102 if (ibmasm_heartbeat_init(sp)) {
103 dev_err(sp->dev, "Failed to allocate heartbeat command\n");
104 goto error_heartbeat;
105 }
106
107 sp->irq = pdev->irq;
108 sp->base_address = ioremap(pci_resource_start(pdev, 0),
109 pci_resource_len(pdev, 0));
110 if (sp->base_address == 0) {
111 dev_err(sp->dev, "Failed to ioremap pci memory\n");
112 result = -ENODEV;
113 goto error_ioremap;
114 }
115
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 result = request_irq(sp->irq, ibmasm_interrupt_handler, SA_SHIRQ, sp->devname, (void*)sp);
117 if (result) {
118 dev_err(sp->dev, "Failed to register interrupt handler\n");
119 goto error_request_irq;
120 }
121
122 enable_sp_interrupts(sp->base_address);
Max Asbock278d72a2005-06-21 17:16:34 -0700123
124 result = ibmasm_init_remote_input_dev(sp);
125 if (result) {
126 dev_err(sp->dev, "Failed to initialize remote queue\n");
127 goto error_send_message;
128 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
130 result = ibmasm_send_driver_vpd(sp);
131 if (result) {
132 dev_err(sp->dev, "Failed to send driver VPD to service processor\n");
133 goto error_send_message;
134 }
135 result = ibmasm_send_os_state(sp, SYSTEM_STATE_OS_UP);
136 if (result) {
137 dev_err(sp->dev, "Failed to send OS state to service processor\n");
138 goto error_send_message;
139 }
140 ibmasmfs_add_sp(sp);
141
142 ibmasm_register_uart(sp);
143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 return 0;
145
146error_send_message:
147 disable_sp_interrupts(sp->base_address);
Max Asbock278d72a2005-06-21 17:16:34 -0700148 ibmasm_free_remote_input_dev(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 free_irq(sp->irq, (void *)sp);
150error_request_irq:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 iounmap(sp->base_address);
152error_ioremap:
153 ibmasm_heartbeat_exit(sp);
154error_heartbeat:
155 ibmasm_event_buffer_exit(sp);
156error_eventbuffer:
Max Asbock278d72a2005-06-21 17:16:34 -0700157 pci_set_drvdata(pdev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 kfree(sp);
159error_kmalloc:
Max Asbock278d72a2005-06-21 17:16:34 -0700160 pci_release_regions(pdev);
161error_resources:
162 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
164 return result;
165}
166
167static void __devexit ibmasm_remove_one(struct pci_dev *pdev)
168{
169 struct service_processor *sp = (struct service_processor *)pci_get_drvdata(pdev);
170
Max Asbock278d72a2005-06-21 17:16:34 -0700171 dbg("Unregistering UART\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 ibmasm_unregister_uart(sp);
Max Asbock278d72a2005-06-21 17:16:34 -0700173 dbg("Sending OS down message\n");
174 if (ibmasm_send_os_state(sp, SYSTEM_STATE_OS_DOWN))
175 err("failed to get repsonse to 'Send OS State' command\n");
176 dbg("Disabling heartbeats\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 ibmasm_heartbeat_exit(sp);
Max Asbock278d72a2005-06-21 17:16:34 -0700178 dbg("Disabling interrupts\n");
179 disable_sp_interrupts(sp->base_address);
180 dbg("Freeing SP irq\n");
181 free_irq(sp->irq, (void *)sp);
182 dbg("Cleaning up\n");
183 ibmasm_free_remote_input_dev(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 iounmap(sp->base_address);
185 ibmasm_event_buffer_exit(sp);
Max Asbock278d72a2005-06-21 17:16:34 -0700186 pci_set_drvdata(pdev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 kfree(sp);
Max Asbock278d72a2005-06-21 17:16:34 -0700188 pci_release_regions(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 pci_disable_device(pdev);
190}
191
192static struct pci_device_id ibmasm_pci_table[] =
193{
194 { PCI_DEVICE(VENDORID_IBM, DEVICEID_RSA) },
195 {},
196};
197
198static struct pci_driver ibmasm_driver = {
199 .name = DRIVER_NAME,
200 .id_table = ibmasm_pci_table,
201 .probe = ibmasm_init_one,
202 .remove = __devexit_p(ibmasm_remove_one),
203};
204
205static void __exit ibmasm_exit (void)
206{
207 ibmasm_unregister_panic_notifier();
208 ibmasmfs_unregister();
209 pci_unregister_driver(&ibmasm_driver);
210 info(DRIVER_DESC " version " DRIVER_VERSION " unloaded");
211}
212
213static int __init ibmasm_init(void)
214{
215 int result;
216
217 result = ibmasmfs_register();
218 if (result) {
219 err("Failed to register ibmasmfs file system");
220 return result;
221 }
222 result = pci_register_driver(&ibmasm_driver);
223 if (result) {
224 ibmasmfs_unregister();
225 return result;
226 }
227 ibmasm_register_panic_notifier();
228 info(DRIVER_DESC " version " DRIVER_VERSION " loaded");
229 return 0;
230}
231
232module_init(ibmasm_init);
233module_exit(ibmasm_exit);
234
235MODULE_AUTHOR(DRIVER_AUTHOR);
236MODULE_DESCRIPTION(DRIVER_DESC);
237MODULE_LICENSE("GPL");
238MODULE_DEVICE_TABLE(pci, ibmasm_pci_table);
239