patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / arch / ppc64 / kernel / HvLpEvent.c
1 /*
2  * Copyright 2001 Mike Corrigan IBM Corp
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version
7  * 2 of the License, or (at your option) any later version.
8  */
9 #include <linux/stddef.h>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <asm/system.h>
13 #include <asm/iSeries/HvLpEvent.h>
14 #include <asm/iSeries/HvCallEvent.h>
15 #include <asm/iSeries/LparData.h>
16
17 /* Array of LpEvent handler functions */
18 LpEventHandler lpEventHandler[HvLpEvent_Type_NumTypes];
19 unsigned lpEventHandlerPaths[HvLpEvent_Type_NumTypes];
20
21 /* Register a handler for an LpEvent type */
22
23 int HvLpEvent_registerHandler( HvLpEvent_Type eventType, LpEventHandler handler )
24 {
25         int rc = 1;
26         if ( eventType < HvLpEvent_Type_NumTypes ) {
27                 lpEventHandler[eventType] = handler;
28                 rc = 0;
29         }
30         return rc;
31         
32 }
33
34 int HvLpEvent_unregisterHandler( HvLpEvent_Type eventType )
35 {
36         int rc = 1;
37         if ( eventType < HvLpEvent_Type_NumTypes ) {
38                 if ( !lpEventHandlerPaths[eventType] ) {
39                         lpEventHandler[eventType] = NULL;
40                         rc = 0;
41                 }
42         }
43         return rc;
44 }
45 EXPORT_SYMBOL(HvLpEvent_registerHandler);
46 EXPORT_SYMBOL(HvLpEvent_unregisterHandler);
47
48 /* (lpIndex is the partition index of the target partition.  
49  * needed only for VirtualIo, VirtualLan and SessionMgr.  Zero
50  * indicates to use our partition index - for the other types)
51  */
52 int HvLpEvent_openPath( HvLpEvent_Type eventType, HvLpIndex lpIndex )
53 {
54         int rc = 1;
55         if ( eventType < HvLpEvent_Type_NumTypes &&
56              lpEventHandler[eventType] ) {
57                 if ( lpIndex == 0 )
58                         lpIndex = itLpNaca.xLpIndex;
59                 HvCallEvent_openLpEventPath( lpIndex, eventType );
60                 ++lpEventHandlerPaths[eventType];
61                 rc = 0;
62         }
63         return rc;
64 }
65
66 int HvLpEvent_closePath( HvLpEvent_Type eventType, HvLpIndex lpIndex )
67 {
68         int rc = 1;
69         if ( eventType < HvLpEvent_Type_NumTypes &&
70              lpEventHandler[eventType] &&
71              lpEventHandlerPaths[eventType] ) {
72                 if ( lpIndex == 0 )
73                         lpIndex = itLpNaca.xLpIndex;
74                 HvCallEvent_closeLpEventPath( lpIndex, eventType );
75                 --lpEventHandlerPaths[eventType];
76                 rc = 0;
77         }
78         return rc;
79 }
80