2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* IBM ASM Service Processor Device Driver
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* Copyright (C) IBM Corporation, 2004
|
|
|
|
*
|
2011-12-29 22:09:01 +00:00
|
|
|
* Author: Max Asböck <amax@us.ibm.com>
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
2007-07-17 11:03:58 +00:00
|
|
|
* This driver is based on code originally written by Pete Reynolds
|
2005-04-16 22:20:36 +00:00
|
|
|
* and others.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The ASM device driver does the following things:
|
|
|
|
*
|
|
|
|
* 1) When loaded it sends a message to the service processor,
|
|
|
|
* indicating that an OS is * running. This causes the service processor
|
2007-07-17 11:03:58 +00:00
|
|
|
* to send periodic heartbeats to the OS.
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
|
|
|
* 2) Answers the periodic heartbeats sent by the service processor.
|
|
|
|
* Failure to do so would result in system reboot.
|
|
|
|
*
|
|
|
|
* 3) Acts as a pass through for dot commands sent from user applications.
|
2007-07-17 11:03:58 +00:00
|
|
|
* The interface for this is the ibmasmfs file system.
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
|
|
|
* 4) Allows user applications to register for event notification. Events
|
|
|
|
* are sent to the driver through interrupts. They can be read from user
|
|
|
|
* space through the ibmasmfs file system.
|
|
|
|
*
|
|
|
|
* 5) Allows user space applications to send heartbeats to the service
|
|
|
|
* processor (aka reverse heartbeats). Again this happens through ibmasmfs.
|
|
|
|
*
|
|
|
|
* 6) Handles remote mouse and keyboard event interrupts and makes them
|
|
|
|
* available to user applications through ibmasmfs.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/init.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include "ibmasm.h"
|
|
|
|
#include "lowlevel.h"
|
|
|
|
#include "remote.h"
|
|
|
|
|
2005-06-22 00:16:34 +00:00
|
|
|
int ibmasm_debug = 0;
|
|
|
|
module_param(ibmasm_debug, int , S_IRUGO | S_IWUSR);
|
|
|
|
MODULE_PARM_DESC(ibmasm_debug, " Set debug mode on or off");
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-11-19 18:23:05 +00:00
|
|
|
static int ibmasm_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-06-22 00:16:34 +00:00
|
|
|
int result;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct service_processor *sp;
|
|
|
|
|
2005-06-22 00:16:34 +00:00
|
|
|
if ((result = pci_enable_device(pdev))) {
|
|
|
|
dev_err(&pdev->dev, "Failed to enable PCI device\n");
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
if ((result = pci_request_regions(pdev, DRIVER_NAME))) {
|
|
|
|
dev_err(&pdev->dev, "Failed to allocate PCI resources\n");
|
|
|
|
goto error_resources;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2005-06-22 00:16:34 +00:00
|
|
|
/* vnc client won't work without bus-mastering */
|
|
|
|
pci_set_master(pdev);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
some kmalloc/memset ->kzalloc (tree wide)
Transform some calls to kmalloc/memset to a single kzalloc (or kcalloc).
Here is a short excerpt of the semantic patch performing
this transformation:
@@
type T2;
expression x;
identifier f,fld;
expression E;
expression E1,E2;
expression e1,e2,e3,y;
statement S;
@@
x =
- kmalloc
+ kzalloc
(E1,E2)
... when != \(x->fld=E;\|y=f(...,x,...);\|f(...,x,...);\|x=E;\|while(...) S\|for(e1;e2;e3) S\)
- memset((T2)x,0,E1);
@@
expression E1,E2,E3;
@@
- kzalloc(E1 * E2,E3)
+ kcalloc(E1,E2,E3)
[akpm@linux-foundation.org: get kcalloc args the right way around]
Signed-off-by: Yoann Padioleau <padator@wanadoo.fr>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Acked-by: Russell King <rmk@arm.linux.org.uk>
Cc: Bryan Wu <bryan.wu@analog.com>
Acked-by: Jiri Slaby <jirislaby@gmail.com>
Cc: Dave Airlie <airlied@linux.ie>
Acked-by: Roland Dreier <rolandd@cisco.com>
Cc: Jiri Kosina <jkosina@suse.cz>
Acked-by: Dmitry Torokhov <dtor@mail.ru>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Acked-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Acked-by: Pierre Ossman <drzeus-list@drzeus.cx>
Cc: Jeff Garzik <jeff@garzik.org>
Cc: "David S. Miller" <davem@davemloft.net>
Acked-by: Greg KH <greg@kroah.com>
Cc: James Bottomley <James.Bottomley@steeleye.com>
Cc: "Antonino A. Daplas" <adaplas@pol.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-19 08:49:03 +00:00
|
|
|
sp = kzalloc(sizeof(struct service_processor), GFP_KERNEL);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (sp == NULL) {
|
|
|
|
dev_err(&pdev->dev, "Failed to allocate memory\n");
|
|
|
|
result = -ENOMEM;
|
|
|
|
goto error_kmalloc;
|
|
|
|
}
|
|
|
|
|
2006-06-27 09:53:55 +00:00
|
|
|
spin_lock_init(&sp->lock);
|
2005-06-22 00:16:34 +00:00
|
|
|
INIT_LIST_HEAD(&sp->command_queue);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
pci_set_drvdata(pdev, (void *)sp);
|
|
|
|
sp->dev = &pdev->dev;
|
|
|
|
sp->number = pdev->bus->number;
|
|
|
|
snprintf(sp->dirname, IBMASM_NAME_SIZE, "%d", sp->number);
|
|
|
|
snprintf(sp->devname, IBMASM_NAME_SIZE, "%s%d", DRIVER_NAME, sp->number);
|
|
|
|
|
|
|
|
if (ibmasm_event_buffer_init(sp)) {
|
|
|
|
dev_err(sp->dev, "Failed to allocate event buffer\n");
|
|
|
|
goto error_eventbuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ibmasm_heartbeat_init(sp)) {
|
|
|
|
dev_err(sp->dev, "Failed to allocate heartbeat command\n");
|
|
|
|
goto error_heartbeat;
|
|
|
|
}
|
|
|
|
|
|
|
|
sp->irq = pdev->irq;
|
2009-01-06 22:40:39 +00:00
|
|
|
sp->base_address = pci_ioremap_bar(pdev, 0);
|
2008-03-29 03:07:48 +00:00
|
|
|
if (!sp->base_address) {
|
2005-04-16 22:20:36 +00:00
|
|
|
dev_err(sp->dev, "Failed to ioremap pci memory\n");
|
|
|
|
result = -ENODEV;
|
|
|
|
goto error_ioremap;
|
|
|
|
}
|
|
|
|
|
2006-07-02 02:29:38 +00:00
|
|
|
result = request_irq(sp->irq, ibmasm_interrupt_handler, IRQF_SHARED, sp->devname, (void*)sp);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (result) {
|
|
|
|
dev_err(sp->dev, "Failed to register interrupt handler\n");
|
|
|
|
goto error_request_irq;
|
|
|
|
}
|
|
|
|
|
|
|
|
enable_sp_interrupts(sp->base_address);
|
2005-06-22 00:16:34 +00:00
|
|
|
|
|
|
|
result = ibmasm_init_remote_input_dev(sp);
|
|
|
|
if (result) {
|
|
|
|
dev_err(sp->dev, "Failed to initialize remote queue\n");
|
|
|
|
goto error_send_message;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
result = ibmasm_send_driver_vpd(sp);
|
|
|
|
if (result) {
|
|
|
|
dev_err(sp->dev, "Failed to send driver VPD to service processor\n");
|
|
|
|
goto error_send_message;
|
|
|
|
}
|
|
|
|
result = ibmasm_send_os_state(sp, SYSTEM_STATE_OS_UP);
|
|
|
|
if (result) {
|
|
|
|
dev_err(sp->dev, "Failed to send OS state to service processor\n");
|
|
|
|
goto error_send_message;
|
|
|
|
}
|
|
|
|
ibmasmfs_add_sp(sp);
|
|
|
|
|
|
|
|
ibmasm_register_uart(sp);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error_send_message:
|
|
|
|
disable_sp_interrupts(sp->base_address);
|
2005-06-22 00:16:34 +00:00
|
|
|
ibmasm_free_remote_input_dev(sp);
|
2005-04-16 22:20:36 +00:00
|
|
|
free_irq(sp->irq, (void *)sp);
|
|
|
|
error_request_irq:
|
|
|
|
iounmap(sp->base_address);
|
|
|
|
error_ioremap:
|
|
|
|
ibmasm_heartbeat_exit(sp);
|
|
|
|
error_heartbeat:
|
|
|
|
ibmasm_event_buffer_exit(sp);
|
|
|
|
error_eventbuffer:
|
|
|
|
kfree(sp);
|
|
|
|
error_kmalloc:
|
2005-06-22 00:16:34 +00:00
|
|
|
pci_release_regions(pdev);
|
|
|
|
error_resources:
|
|
|
|
pci_disable_device(pdev);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-11-19 18:26:02 +00:00
|
|
|
static void ibmasm_remove_one(struct pci_dev *pdev)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2013-09-09 05:15:52 +00:00
|
|
|
struct service_processor *sp = pci_get_drvdata(pdev);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-06-22 00:16:34 +00:00
|
|
|
dbg("Unregistering UART\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
ibmasm_unregister_uart(sp);
|
2005-06-22 00:16:34 +00:00
|
|
|
dbg("Sending OS down message\n");
|
|
|
|
if (ibmasm_send_os_state(sp, SYSTEM_STATE_OS_DOWN))
|
|
|
|
err("failed to get repsonse to 'Send OS State' command\n");
|
|
|
|
dbg("Disabling heartbeats\n");
|
|
|
|
ibmasm_heartbeat_exit(sp);
|
|
|
|
dbg("Disabling interrupts\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
disable_sp_interrupts(sp->base_address);
|
2005-06-22 00:16:34 +00:00
|
|
|
dbg("Freeing SP irq\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
free_irq(sp->irq, (void *)sp);
|
2005-06-22 00:16:34 +00:00
|
|
|
dbg("Cleaning up\n");
|
|
|
|
ibmasm_free_remote_input_dev(sp);
|
2005-04-16 22:20:36 +00:00
|
|
|
iounmap(sp->base_address);
|
|
|
|
ibmasm_event_buffer_exit(sp);
|
|
|
|
kfree(sp);
|
2005-06-22 00:16:34 +00:00
|
|
|
pci_release_regions(pdev);
|
2005-04-16 22:20:36 +00:00
|
|
|
pci_disable_device(pdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct pci_device_id ibmasm_pci_table[] =
|
|
|
|
{
|
|
|
|
{ PCI_DEVICE(VENDORID_IBM, DEVICEID_RSA) },
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct pci_driver ibmasm_driver = {
|
|
|
|
.name = DRIVER_NAME,
|
|
|
|
.id_table = ibmasm_pci_table,
|
|
|
|
.probe = ibmasm_init_one,
|
2012-11-19 18:21:23 +00:00
|
|
|
.remove = ibmasm_remove_one,
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void __exit ibmasm_exit (void)
|
|
|
|
{
|
|
|
|
ibmasm_unregister_panic_notifier();
|
|
|
|
ibmasmfs_unregister();
|
|
|
|
pci_unregister_driver(&ibmasm_driver);
|
|
|
|
info(DRIVER_DESC " version " DRIVER_VERSION " unloaded");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init ibmasm_init(void)
|
|
|
|
{
|
2012-03-17 05:50:32 +00:00
|
|
|
int result = pci_register_driver(&ibmasm_driver);
|
|
|
|
if (result)
|
|
|
|
return result;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
result = ibmasmfs_register();
|
|
|
|
if (result) {
|
2012-03-17 05:50:32 +00:00
|
|
|
pci_unregister_driver(&ibmasm_driver);
|
2005-04-16 22:20:36 +00:00
|
|
|
err("Failed to register ibmasmfs file system");
|
|
|
|
return result;
|
|
|
|
}
|
2012-03-17 05:50:32 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
ibmasm_register_panic_notifier();
|
|
|
|
info(DRIVER_DESC " version " DRIVER_VERSION " loaded");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(ibmasm_init);
|
|
|
|
module_exit(ibmasm_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR(DRIVER_AUTHOR);
|
|
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_DEVICE_TABLE(pci, ibmasm_pci_table);
|
|
|
|
|