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 <asm/system.h>
12 #include <asm/iSeries/HvLpEvent.h>
13 #include <asm/iSeries/HvCallEvent.h>
14 #include <asm/iSeries/LparData.h>
15
16 /* Array of LpEvent handler functions */
17 LpEventHandler lpEventHandler[HvLpEvent_Type_NumTypes];
18 unsigned lpEventHandlerPaths[HvLpEvent_Type_NumTypes];
19
20 /* Register a handler for an LpEvent type */
21
HvLpEvent_registerHandler(HvLpEvent_Type eventType,LpEventHandler handler)22 int HvLpEvent_registerHandler( HvLpEvent_Type eventType, LpEventHandler handler )
23 {
24 int rc = 1;
25 if ( eventType < HvLpEvent_Type_NumTypes ) {
26 lpEventHandler[eventType] = handler;
27 rc = 0;
28 }
29 return rc;
30
31 }
32
HvLpEvent_unregisterHandler(HvLpEvent_Type eventType)33 int HvLpEvent_unregisterHandler( HvLpEvent_Type eventType )
34 {
35 int rc = 1;
36 if ( eventType < HvLpEvent_Type_NumTypes ) {
37 if ( !lpEventHandlerPaths[eventType] ) {
38 lpEventHandler[eventType] = NULL;
39 rc = 0;
40 }
41 }
42 return rc;
43 }
44
45 /* (lpIndex is the partition index of the target partition.
46 * needed only for VirtualIo, VirtualLan and SessionMgr. Zero
47 * indicates to use our partition index - for the other types)
48 */
HvLpEvent_openPath(HvLpEvent_Type eventType,HvLpIndex lpIndex)49 int HvLpEvent_openPath( HvLpEvent_Type eventType, HvLpIndex lpIndex )
50 {
51 int rc = 1;
52 if ( eventType < HvLpEvent_Type_NumTypes &&
53 lpEventHandler[eventType] ) {
54 if ( lpIndex == 0 )
55 lpIndex = itLpNaca.xLpIndex;
56 HvCallEvent_openLpEventPath( lpIndex, eventType );
57 ++lpEventHandlerPaths[eventType];
58 rc = 0;
59 }
60 return rc;
61 }
62
HvLpEvent_closePath(HvLpEvent_Type eventType,HvLpIndex lpIndex)63 int HvLpEvent_closePath( HvLpEvent_Type eventType, HvLpIndex lpIndex )
64 {
65 int rc = 1;
66 if ( eventType < HvLpEvent_Type_NumTypes &&
67 lpEventHandler[eventType] &&
68 lpEventHandlerPaths[eventType] ) {
69 if ( lpIndex == 0 )
70 lpIndex = itLpNaca.xLpIndex;
71 HvCallEvent_closeLpEventPath( lpIndex, eventType );
72 --lpEventHandlerPaths[eventType];
73 rc = 0;
74 }
75 return rc;
76 }
77
78