11da177e4SLinus Torvalds 21da177e4SLinus Torvalds /* 31da177e4SLinus Torvalds * IBM ASM Service Processor Device Driver 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify 61da177e4SLinus Torvalds * it under the terms of the GNU General Public License as published by 71da177e4SLinus Torvalds * the Free Software Foundation; either version 2 of the License, or 81da177e4SLinus Torvalds * (at your option) any later version. 91da177e4SLinus Torvalds * 101da177e4SLinus Torvalds * This program is distributed in the hope that it will be useful, 111da177e4SLinus Torvalds * but WITHOUT ANY WARRANTY; without even the implied warranty of 121da177e4SLinus Torvalds * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 131da177e4SLinus Torvalds * GNU General Public License for more details. 141da177e4SLinus Torvalds * 151da177e4SLinus Torvalds * You should have received a copy of the GNU General Public License 161da177e4SLinus Torvalds * along with this program; if not, write to the Free Software 171da177e4SLinus Torvalds * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 181da177e4SLinus Torvalds * 191da177e4SLinus Torvalds * Copyright (C) IBM Corporation, 2004 201da177e4SLinus Torvalds * 21d36b6910SAl Viro * Author: Max Asböck <amax@us.ibm.com> 221da177e4SLinus Torvalds * 231da177e4SLinus Torvalds * This driver is based on code originally written by Pete Reynolds 241da177e4SLinus Torvalds * and others. 251da177e4SLinus Torvalds * 261da177e4SLinus Torvalds */ 271da177e4SLinus Torvalds 281da177e4SLinus Torvalds /* 291da177e4SLinus Torvalds * The ASM device driver does the following things: 301da177e4SLinus Torvalds * 311da177e4SLinus Torvalds * 1) When loaded it sends a message to the service processor, 321da177e4SLinus Torvalds * indicating that an OS is * running. This causes the service processor 331da177e4SLinus Torvalds * to send periodic heartbeats to the OS. 341da177e4SLinus Torvalds * 351da177e4SLinus Torvalds * 2) Answers the periodic heartbeats sent by the service processor. 361da177e4SLinus Torvalds * Failure to do so would result in system reboot. 371da177e4SLinus Torvalds * 381da177e4SLinus Torvalds * 3) Acts as a pass through for dot commands sent from user applications. 391da177e4SLinus Torvalds * The interface for this is the ibmasmfs file system. 401da177e4SLinus Torvalds * 411da177e4SLinus Torvalds * 4) Allows user applications to register for event notification. Events 421da177e4SLinus Torvalds * are sent to the driver through interrupts. They can be read from user 431da177e4SLinus Torvalds * space through the ibmasmfs file system. 441da177e4SLinus Torvalds * 451da177e4SLinus Torvalds * 5) Allows user space applications to send heartbeats to the service 461da177e4SLinus Torvalds * processor (aka reverse heartbeats). Again this happens through ibmasmfs. 471da177e4SLinus Torvalds * 481da177e4SLinus Torvalds * 6) Handles remote mouse and keyboard event interrupts and makes them 491da177e4SLinus Torvalds * available to user applications through ibmasmfs. 501da177e4SLinus Torvalds * 511da177e4SLinus Torvalds */ 521da177e4SLinus Torvalds 531da177e4SLinus Torvalds #include <linux/pci.h> 541da177e4SLinus Torvalds #include <linux/init.h> 555a0e3ad6STejun Heo #include <linux/slab.h> 561da177e4SLinus Torvalds #include "ibmasm.h" 571da177e4SLinus Torvalds #include "lowlevel.h" 581da177e4SLinus Torvalds #include "remote.h" 591da177e4SLinus Torvalds 60278d72aeSMax Asbock int ibmasm_debug = 0; 61278d72aeSMax Asbock module_param(ibmasm_debug, int , S_IRUGO | S_IWUSR); 62278d72aeSMax Asbock MODULE_PARM_DESC(ibmasm_debug, " Set debug mode on or off"); 63278d72aeSMax Asbock 641da177e4SLinus Torvalds 6580c8ae28SBill Pemberton static int ibmasm_init_one(struct pci_dev *pdev, const struct pci_device_id *id) 661da177e4SLinus Torvalds { 67278d72aeSMax Asbock int result; 681da177e4SLinus Torvalds struct service_processor *sp; 691da177e4SLinus Torvalds 70278d72aeSMax Asbock if ((result = pci_enable_device(pdev))) { 71278d72aeSMax Asbock dev_err(&pdev->dev, "Failed to enable PCI device\n"); 72278d72aeSMax Asbock return result; 731da177e4SLinus Torvalds } 74278d72aeSMax Asbock if ((result = pci_request_regions(pdev, DRIVER_NAME))) { 75278d72aeSMax Asbock dev_err(&pdev->dev, "Failed to allocate PCI resources\n"); 76278d72aeSMax Asbock goto error_resources; 77278d72aeSMax Asbock } 78278d72aeSMax Asbock /* vnc client won't work without bus-mastering */ 79278d72aeSMax Asbock pci_set_master(pdev); 801da177e4SLinus Torvalds 81dd00cc48SYoann Padioleau sp = kzalloc(sizeof(struct service_processor), GFP_KERNEL); 821da177e4SLinus Torvalds if (sp == NULL) { 831da177e4SLinus Torvalds dev_err(&pdev->dev, "Failed to allocate memory\n"); 841da177e4SLinus Torvalds result = -ENOMEM; 851da177e4SLinus Torvalds goto error_kmalloc; 861da177e4SLinus Torvalds } 871da177e4SLinus Torvalds 8834af946aSIngo Molnar spin_lock_init(&sp->lock); 89278d72aeSMax Asbock INIT_LIST_HEAD(&sp->command_queue); 90278d72aeSMax Asbock 911da177e4SLinus Torvalds pci_set_drvdata(pdev, (void *)sp); 921da177e4SLinus Torvalds sp->dev = &pdev->dev; 931da177e4SLinus Torvalds sp->number = pdev->bus->number; 941da177e4SLinus Torvalds snprintf(sp->dirname, IBMASM_NAME_SIZE, "%d", sp->number); 951da177e4SLinus Torvalds snprintf(sp->devname, IBMASM_NAME_SIZE, "%s%d", DRIVER_NAME, sp->number); 961da177e4SLinus Torvalds 97*f403f85fSAnton Vasilyev result = ibmasm_event_buffer_init(sp); 98*f403f85fSAnton Vasilyev if (result) { 991da177e4SLinus Torvalds dev_err(sp->dev, "Failed to allocate event buffer\n"); 1001da177e4SLinus Torvalds goto error_eventbuffer; 1011da177e4SLinus Torvalds } 1021da177e4SLinus Torvalds 103*f403f85fSAnton Vasilyev result = ibmasm_heartbeat_init(sp); 104*f403f85fSAnton Vasilyev if (result) { 1051da177e4SLinus Torvalds dev_err(sp->dev, "Failed to allocate heartbeat command\n"); 1061da177e4SLinus Torvalds goto error_heartbeat; 1071da177e4SLinus Torvalds } 1081da177e4SLinus Torvalds 1091da177e4SLinus Torvalds sp->irq = pdev->irq; 110bdbeed75SArjan van de Ven sp->base_address = pci_ioremap_bar(pdev, 0); 1115cf83b9bSAl Viro if (!sp->base_address) { 1121da177e4SLinus Torvalds dev_err(sp->dev, "Failed to ioremap pci memory\n"); 1131da177e4SLinus Torvalds result = -ENODEV; 1141da177e4SLinus Torvalds goto error_ioremap; 1151da177e4SLinus Torvalds } 1161da177e4SLinus Torvalds 117dace1453SThomas Gleixner result = request_irq(sp->irq, ibmasm_interrupt_handler, IRQF_SHARED, sp->devname, (void*)sp); 1181da177e4SLinus Torvalds if (result) { 1191da177e4SLinus Torvalds dev_err(sp->dev, "Failed to register interrupt handler\n"); 1201da177e4SLinus Torvalds goto error_request_irq; 1211da177e4SLinus Torvalds } 1221da177e4SLinus Torvalds 1231da177e4SLinus Torvalds enable_sp_interrupts(sp->base_address); 124278d72aeSMax Asbock 125278d72aeSMax Asbock result = ibmasm_init_remote_input_dev(sp); 126278d72aeSMax Asbock if (result) { 127278d72aeSMax Asbock dev_err(sp->dev, "Failed to initialize remote queue\n"); 128278d72aeSMax Asbock goto error_send_message; 129278d72aeSMax Asbock } 1301da177e4SLinus Torvalds 1311da177e4SLinus Torvalds result = ibmasm_send_driver_vpd(sp); 1321da177e4SLinus Torvalds if (result) { 1331da177e4SLinus Torvalds dev_err(sp->dev, "Failed to send driver VPD to service processor\n"); 1341da177e4SLinus Torvalds goto error_send_message; 1351da177e4SLinus Torvalds } 1361da177e4SLinus Torvalds result = ibmasm_send_os_state(sp, SYSTEM_STATE_OS_UP); 1371da177e4SLinus Torvalds if (result) { 1381da177e4SLinus Torvalds dev_err(sp->dev, "Failed to send OS state to service processor\n"); 1391da177e4SLinus Torvalds goto error_send_message; 1401da177e4SLinus Torvalds } 1411da177e4SLinus Torvalds ibmasmfs_add_sp(sp); 1421da177e4SLinus Torvalds 1431da177e4SLinus Torvalds ibmasm_register_uart(sp); 1441da177e4SLinus Torvalds 1451da177e4SLinus Torvalds return 0; 1461da177e4SLinus Torvalds 1471da177e4SLinus Torvalds error_send_message: 1481da177e4SLinus Torvalds disable_sp_interrupts(sp->base_address); 149278d72aeSMax Asbock ibmasm_free_remote_input_dev(sp); 1501da177e4SLinus Torvalds free_irq(sp->irq, (void *)sp); 1511da177e4SLinus Torvalds error_request_irq: 1521da177e4SLinus Torvalds iounmap(sp->base_address); 1531da177e4SLinus Torvalds error_ioremap: 1541da177e4SLinus Torvalds ibmasm_heartbeat_exit(sp); 1551da177e4SLinus Torvalds error_heartbeat: 1561da177e4SLinus Torvalds ibmasm_event_buffer_exit(sp); 1571da177e4SLinus Torvalds error_eventbuffer: 1581da177e4SLinus Torvalds kfree(sp); 1591da177e4SLinus Torvalds error_kmalloc: 160278d72aeSMax Asbock pci_release_regions(pdev); 161278d72aeSMax Asbock error_resources: 1621da177e4SLinus Torvalds pci_disable_device(pdev); 1631da177e4SLinus Torvalds 1641da177e4SLinus Torvalds return result; 1651da177e4SLinus Torvalds } 1661da177e4SLinus Torvalds 167486a5c28SBill Pemberton static void ibmasm_remove_one(struct pci_dev *pdev) 1681da177e4SLinus Torvalds { 169bbf831dfSJingoo Han struct service_processor *sp = pci_get_drvdata(pdev); 1701da177e4SLinus Torvalds 171278d72aeSMax Asbock dbg("Unregistering UART\n"); 1721da177e4SLinus Torvalds ibmasm_unregister_uart(sp); 173278d72aeSMax Asbock dbg("Sending OS down message\n"); 174278d72aeSMax Asbock if (ibmasm_send_os_state(sp, SYSTEM_STATE_OS_DOWN)) 175ecbf1288SColin Ian King err("failed to get response to 'Send OS State' command\n"); 176278d72aeSMax Asbock dbg("Disabling heartbeats\n"); 1771da177e4SLinus Torvalds ibmasm_heartbeat_exit(sp); 178278d72aeSMax Asbock dbg("Disabling interrupts\n"); 179278d72aeSMax Asbock disable_sp_interrupts(sp->base_address); 180278d72aeSMax Asbock dbg("Freeing SP irq\n"); 181278d72aeSMax Asbock free_irq(sp->irq, (void *)sp); 182278d72aeSMax Asbock dbg("Cleaning up\n"); 183278d72aeSMax Asbock ibmasm_free_remote_input_dev(sp); 1841da177e4SLinus Torvalds iounmap(sp->base_address); 1851da177e4SLinus Torvalds ibmasm_event_buffer_exit(sp); 1861da177e4SLinus Torvalds kfree(sp); 187278d72aeSMax Asbock pci_release_regions(pdev); 1881da177e4SLinus Torvalds pci_disable_device(pdev); 1891da177e4SLinus Torvalds } 1901da177e4SLinus Torvalds 1911da177e4SLinus Torvalds static struct pci_device_id ibmasm_pci_table[] = 1921da177e4SLinus Torvalds { 1931da177e4SLinus Torvalds { PCI_DEVICE(VENDORID_IBM, DEVICEID_RSA) }, 1941da177e4SLinus Torvalds {}, 1951da177e4SLinus Torvalds }; 1961da177e4SLinus Torvalds 1971da177e4SLinus Torvalds static struct pci_driver ibmasm_driver = { 1981da177e4SLinus Torvalds .name = DRIVER_NAME, 1991da177e4SLinus Torvalds .id_table = ibmasm_pci_table, 2001da177e4SLinus Torvalds .probe = ibmasm_init_one, 2012d6bed9cSBill Pemberton .remove = ibmasm_remove_one, 2021da177e4SLinus Torvalds }; 2031da177e4SLinus Torvalds 2041da177e4SLinus Torvalds static void __exit ibmasm_exit (void) 2051da177e4SLinus Torvalds { 2061da177e4SLinus Torvalds ibmasm_unregister_panic_notifier(); 2071da177e4SLinus Torvalds ibmasmfs_unregister(); 2081da177e4SLinus Torvalds pci_unregister_driver(&ibmasm_driver); 2091da177e4SLinus Torvalds info(DRIVER_DESC " version " DRIVER_VERSION " unloaded"); 2101da177e4SLinus Torvalds } 2111da177e4SLinus Torvalds 2121da177e4SLinus Torvalds static int __init ibmasm_init(void) 2131da177e4SLinus Torvalds { 214ea23b453SAl Viro int result = pci_register_driver(&ibmasm_driver); 215ea23b453SAl Viro if (result) 216ea23b453SAl Viro return result; 2171da177e4SLinus Torvalds 2181da177e4SLinus Torvalds result = ibmasmfs_register(); 2191da177e4SLinus Torvalds if (result) { 220ea23b453SAl Viro pci_unregister_driver(&ibmasm_driver); 2211da177e4SLinus Torvalds err("Failed to register ibmasmfs file system"); 2221da177e4SLinus Torvalds return result; 2231da177e4SLinus Torvalds } 224ea23b453SAl Viro 2251da177e4SLinus Torvalds ibmasm_register_panic_notifier(); 2261da177e4SLinus Torvalds info(DRIVER_DESC " version " DRIVER_VERSION " loaded"); 2271da177e4SLinus Torvalds return 0; 2281da177e4SLinus Torvalds } 2291da177e4SLinus Torvalds 2301da177e4SLinus Torvalds module_init(ibmasm_init); 2311da177e4SLinus Torvalds module_exit(ibmasm_exit); 2321da177e4SLinus Torvalds 2331da177e4SLinus Torvalds MODULE_AUTHOR(DRIVER_AUTHOR); 2341da177e4SLinus Torvalds MODULE_DESCRIPTION(DRIVER_DESC); 2351da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 2361da177e4SLinus Torvalds MODULE_DEVICE_TABLE(pci, ibmasm_pci_table); 2371da177e4SLinus Torvalds 238