1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * IBM ASM Service Processor Device Driver
6 * Copyright (C) IBM Corporation, 2004
10 * This driver is based on code originally written by Pete Reynolds
15 * The ASM device driver does the following things:
17 * 1) When loaded it sends a message to the service processor,
18 * indicating that an OS is * running. This causes the service processor
19 * to send periodic heartbeats to the OS.
21 * 2) Answers the periodic heartbeats sent by the service processor.
22 * Failure to do so would result in system reboot.
24 * 3) Acts as a pass through for dot commands sent from user applications.
25 * The interface for this is the ibmasmfs file system.
27 * 4) Allows user applications to register for event notification. Events
28 * are sent to the driver through interrupts. They can be read from user
29 * space through the ibmasmfs file system.
31 * 5) Allows user space applications to send heartbeats to the service
32 * processor (aka reverse heartbeats). Again this happens through ibmasmfs.
34 * 6) Handles remote mouse and keyboard event interrupts and makes them
35 * available to user applications through ibmasmfs.
39 #include <linux/pci.h>
40 #include <linux/init.h>
41 #include <linux/slab.h>
47 module_param(ibmasm_debug, int , S_IRUGO | S_IWUSR);
48 MODULE_PARM_DESC(ibmasm_debug, " Set debug mode on or off");
51 static int ibmasm_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
54 struct service_processor *sp;
56 if ((result = pci_enable_device(pdev))) {
57 dev_err(&pdev->dev, "Failed to enable PCI device\n");
60 if ((result = pci_request_regions(pdev, DRIVER_NAME))) {
61 dev_err(&pdev->dev, "Failed to allocate PCI resources\n");
64 /* vnc client won't work without bus-mastering */
67 sp = kzalloc(sizeof(struct service_processor), GFP_KERNEL);
69 dev_err(&pdev->dev, "Failed to allocate memory\n");
74 spin_lock_init(&sp->lock);
75 INIT_LIST_HEAD(&sp->command_queue);
77 pci_set_drvdata(pdev, (void *)sp);
79 sp->number = pdev->bus->number;
80 snprintf(sp->dirname, IBMASM_NAME_SIZE, "%d", sp->number);
81 snprintf(sp->devname, IBMASM_NAME_SIZE, "%s%d", DRIVER_NAME, sp->number);
83 result = ibmasm_event_buffer_init(sp);
85 dev_err(sp->dev, "Failed to allocate event buffer\n");
86 goto error_eventbuffer;
89 result = ibmasm_heartbeat_init(sp);
91 dev_err(sp->dev, "Failed to allocate heartbeat command\n");
96 sp->base_address = pci_ioremap_bar(pdev, 0);
97 if (!sp->base_address) {
98 dev_err(sp->dev, "Failed to ioremap pci memory\n");
103 result = request_irq(sp->irq, ibmasm_interrupt_handler, IRQF_SHARED, sp->devname, (void*)sp);
105 dev_err(sp->dev, "Failed to register interrupt handler\n");
106 goto error_request_irq;
109 enable_sp_interrupts(sp->base_address);
111 result = ibmasm_init_remote_input_dev(sp);
113 dev_err(sp->dev, "Failed to initialize remote queue\n");
114 goto error_send_message;
117 result = ibmasm_send_driver_vpd(sp);
119 dev_err(sp->dev, "Failed to send driver VPD to service processor\n");
120 goto error_send_message;
122 result = ibmasm_send_os_state(sp, SYSTEM_STATE_OS_UP);
124 dev_err(sp->dev, "Failed to send OS state to service processor\n");
125 goto error_send_message;
129 ibmasm_register_uart(sp);
134 disable_sp_interrupts(sp->base_address);
135 ibmasm_free_remote_input_dev(sp);
136 free_irq(sp->irq, (void *)sp);
138 iounmap(sp->base_address);
140 ibmasm_heartbeat_exit(sp);
142 ibmasm_event_buffer_exit(sp);
146 pci_release_regions(pdev);
148 pci_disable_device(pdev);
153 static void ibmasm_remove_one(struct pci_dev *pdev)
155 struct service_processor *sp = pci_get_drvdata(pdev);
157 dbg("Unregistering UART\n");
158 ibmasm_unregister_uart(sp);
159 dbg("Sending OS down message\n");
160 if (ibmasm_send_os_state(sp, SYSTEM_STATE_OS_DOWN))
161 err("failed to get response to 'Send OS State' command\n");
162 dbg("Disabling heartbeats\n");
163 ibmasm_heartbeat_exit(sp);
164 dbg("Disabling interrupts\n");
165 disable_sp_interrupts(sp->base_address);
166 dbg("Freeing SP irq\n");
167 free_irq(sp->irq, (void *)sp);
168 dbg("Cleaning up\n");
169 ibmasm_free_remote_input_dev(sp);
170 iounmap(sp->base_address);
171 ibmasm_event_buffer_exit(sp);
173 pci_release_regions(pdev);
174 pci_disable_device(pdev);
177 static struct pci_device_id ibmasm_pci_table[] =
179 { PCI_DEVICE(VENDORID_IBM, DEVICEID_RSA) },
183 static struct pci_driver ibmasm_driver = {
185 .id_table = ibmasm_pci_table,
186 .probe = ibmasm_init_one,
187 .remove = ibmasm_remove_one,
190 static void __exit ibmasm_exit (void)
192 ibmasm_unregister_panic_notifier();
193 ibmasmfs_unregister();
194 pci_unregister_driver(&ibmasm_driver);
195 info(DRIVER_DESC " version " DRIVER_VERSION " unloaded");
198 static int __init ibmasm_init(void)
200 int result = pci_register_driver(&ibmasm_driver);
204 result = ibmasmfs_register();
206 pci_unregister_driver(&ibmasm_driver);
207 err("Failed to register ibmasmfs file system");
211 ibmasm_register_panic_notifier();
212 info(DRIVER_DESC " version " DRIVER_VERSION " loaded");
216 module_init(ibmasm_init);
217 module_exit(ibmasm_exit);
219 MODULE_AUTHOR(DRIVER_AUTHOR);
220 MODULE_DESCRIPTION(DRIVER_DESC);
221 MODULE_LICENSE("GPL");
222 MODULE_DEVICE_TABLE(pci, ibmasm_pci_table);