Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame^] | 1 | |
| 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 | |
| 59 | |
| 60 | static int __devinit ibmasm_init_one(struct pci_dev *pdev, const struct pci_device_id *id) |
| 61 | { |
| 62 | int err, result = -ENOMEM; |
| 63 | struct service_processor *sp; |
| 64 | |
| 65 | if ((err = pci_enable_device(pdev))) { |
| 66 | printk(KERN_ERR "%s: can't enable PCI device at %s\n", |
| 67 | DRIVER_NAME, pci_name(pdev)); |
| 68 | return err; |
| 69 | } |
| 70 | |
| 71 | sp = kmalloc(sizeof(struct service_processor), GFP_KERNEL); |
| 72 | if (sp == NULL) { |
| 73 | dev_err(&pdev->dev, "Failed to allocate memory\n"); |
| 74 | result = -ENOMEM; |
| 75 | goto error_kmalloc; |
| 76 | } |
| 77 | memset(sp, 0, sizeof(struct service_processor)); |
| 78 | |
| 79 | pci_set_drvdata(pdev, (void *)sp); |
| 80 | sp->dev = &pdev->dev; |
| 81 | sp->number = pdev->bus->number; |
| 82 | snprintf(sp->dirname, IBMASM_NAME_SIZE, "%d", sp->number); |
| 83 | snprintf(sp->devname, IBMASM_NAME_SIZE, "%s%d", DRIVER_NAME, sp->number); |
| 84 | |
| 85 | if (ibmasm_event_buffer_init(sp)) { |
| 86 | dev_err(sp->dev, "Failed to allocate event buffer\n"); |
| 87 | goto error_eventbuffer; |
| 88 | } |
| 89 | |
| 90 | if (ibmasm_heartbeat_init(sp)) { |
| 91 | dev_err(sp->dev, "Failed to allocate heartbeat command\n"); |
| 92 | goto error_heartbeat; |
| 93 | } |
| 94 | |
| 95 | sp->irq = pdev->irq; |
| 96 | sp->base_address = ioremap(pci_resource_start(pdev, 0), |
| 97 | pci_resource_len(pdev, 0)); |
| 98 | if (sp->base_address == 0) { |
| 99 | dev_err(sp->dev, "Failed to ioremap pci memory\n"); |
| 100 | result = -ENODEV; |
| 101 | goto error_ioremap; |
| 102 | } |
| 103 | |
| 104 | result = ibmasm_init_remote_queue(sp); |
| 105 | if (result) { |
| 106 | dev_err(sp->dev, "Failed to initialize remote queue\n"); |
| 107 | goto error_remote_queue; |
| 108 | } |
| 109 | |
| 110 | spin_lock_init(&sp->lock); |
| 111 | INIT_LIST_HEAD(&sp->command_queue); |
| 112 | |
| 113 | result = request_irq(sp->irq, ibmasm_interrupt_handler, SA_SHIRQ, sp->devname, (void*)sp); |
| 114 | if (result) { |
| 115 | dev_err(sp->dev, "Failed to register interrupt handler\n"); |
| 116 | goto error_request_irq; |
| 117 | } |
| 118 | |
| 119 | enable_sp_interrupts(sp->base_address); |
| 120 | disable_mouse_interrupts(sp); |
| 121 | |
| 122 | result = ibmasm_send_driver_vpd(sp); |
| 123 | if (result) { |
| 124 | dev_err(sp->dev, "Failed to send driver VPD to service processor\n"); |
| 125 | goto error_send_message; |
| 126 | } |
| 127 | result = ibmasm_send_os_state(sp, SYSTEM_STATE_OS_UP); |
| 128 | if (result) { |
| 129 | dev_err(sp->dev, "Failed to send OS state to service processor\n"); |
| 130 | goto error_send_message; |
| 131 | } |
| 132 | ibmasmfs_add_sp(sp); |
| 133 | |
| 134 | ibmasm_register_uart(sp); |
| 135 | |
| 136 | dev_printk(KERN_DEBUG, &pdev->dev, "WARNING: This software may not be supported or function\n"); |
| 137 | dev_printk(KERN_DEBUG, &pdev->dev, "correctly on your IBM server. Please consult the IBM\n"); |
| 138 | dev_printk(KERN_DEBUG, &pdev->dev, "ServerProven website\n"); |
| 139 | dev_printk(KERN_DEBUG, &pdev->dev, "http://www.pc.ibm.com/ww/eserver/xseries/serverproven\n"); |
| 140 | dev_printk(KERN_DEBUG, &pdev->dev, "for information on the specific driver level and support\n"); |
| 141 | dev_printk(KERN_DEBUG, &pdev->dev, "statement for your IBM server.\n"); |
| 142 | |
| 143 | return 0; |
| 144 | |
| 145 | error_send_message: |
| 146 | disable_sp_interrupts(sp->base_address); |
| 147 | free_irq(sp->irq, (void *)sp); |
| 148 | error_request_irq: |
| 149 | ibmasm_free_remote_queue(sp); |
| 150 | error_remote_queue: |
| 151 | iounmap(sp->base_address); |
| 152 | error_ioremap: |
| 153 | ibmasm_heartbeat_exit(sp); |
| 154 | error_heartbeat: |
| 155 | ibmasm_event_buffer_exit(sp); |
| 156 | error_eventbuffer: |
| 157 | kfree(sp); |
| 158 | error_kmalloc: |
| 159 | pci_disable_device(pdev); |
| 160 | |
| 161 | return result; |
| 162 | } |
| 163 | |
| 164 | static void __devexit ibmasm_remove_one(struct pci_dev *pdev) |
| 165 | { |
| 166 | struct service_processor *sp = (struct service_processor *)pci_get_drvdata(pdev); |
| 167 | |
| 168 | ibmasm_unregister_uart(sp); |
| 169 | ibmasm_send_os_state(sp, SYSTEM_STATE_OS_DOWN); |
| 170 | disable_sp_interrupts(sp->base_address); |
| 171 | disable_mouse_interrupts(sp); |
| 172 | free_irq(sp->irq, (void *)sp); |
| 173 | ibmasm_heartbeat_exit(sp); |
| 174 | ibmasm_free_remote_queue(sp); |
| 175 | iounmap(sp->base_address); |
| 176 | ibmasm_event_buffer_exit(sp); |
| 177 | kfree(sp); |
| 178 | pci_disable_device(pdev); |
| 179 | } |
| 180 | |
| 181 | static struct pci_device_id ibmasm_pci_table[] = |
| 182 | { |
| 183 | { PCI_DEVICE(VENDORID_IBM, DEVICEID_RSA) }, |
| 184 | {}, |
| 185 | }; |
| 186 | |
| 187 | static struct pci_driver ibmasm_driver = { |
| 188 | .name = DRIVER_NAME, |
| 189 | .id_table = ibmasm_pci_table, |
| 190 | .probe = ibmasm_init_one, |
| 191 | .remove = __devexit_p(ibmasm_remove_one), |
| 192 | }; |
| 193 | |
| 194 | static void __exit ibmasm_exit (void) |
| 195 | { |
| 196 | ibmasm_unregister_panic_notifier(); |
| 197 | ibmasmfs_unregister(); |
| 198 | pci_unregister_driver(&ibmasm_driver); |
| 199 | info(DRIVER_DESC " version " DRIVER_VERSION " unloaded"); |
| 200 | } |
| 201 | |
| 202 | static int __init ibmasm_init(void) |
| 203 | { |
| 204 | int result; |
| 205 | |
| 206 | result = ibmasmfs_register(); |
| 207 | if (result) { |
| 208 | err("Failed to register ibmasmfs file system"); |
| 209 | return result; |
| 210 | } |
| 211 | result = pci_register_driver(&ibmasm_driver); |
| 212 | if (result) { |
| 213 | ibmasmfs_unregister(); |
| 214 | return result; |
| 215 | } |
| 216 | ibmasm_register_panic_notifier(); |
| 217 | info(DRIVER_DESC " version " DRIVER_VERSION " loaded"); |
| 218 | return 0; |
| 219 | } |
| 220 | |
| 221 | module_init(ibmasm_init); |
| 222 | module_exit(ibmasm_exit); |
| 223 | |
| 224 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 225 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 226 | MODULE_LICENSE("GPL"); |
| 227 | MODULE_DEVICE_TABLE(pci, ibmasm_pci_table); |
| 228 | |