2 * Copyright (C) 2001 Troy D. Armstrong IBM Corporation
3 * Copyright (C) 2004-2005 Stephen Rothwell IBM Corporation
5 * This modules exists as an interface between a Linux secondary partition
6 * running on an iSeries and the primary partition's Virtual Service
7 * Processor (VSP) object. The VSP has final authority over powering on/off
8 * all partitions in the iSeries. It also provides miscellaneous low-level
9 * machine facility type operations.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include <linux/types.h>
28 #include <linux/errno.h>
29 #include <linux/kernel.h>
30 #include <linux/init.h>
31 #include <linux/completion.h>
32 #include <linux/delay.h>
33 #include <linux/dma-mapping.h>
34 #include <linux/bcd.h>
35 #include <linux/rtc.h>
36 #include <linux/slab.h>
39 #include <asm/uaccess.h>
41 #include <asm/abs_addr.h>
42 #include <asm/firmware.h>
43 #include <asm/iseries/mf.h>
44 #include <asm/iseries/hv_lp_config.h>
45 #include <asm/iseries/hv_lp_event.h>
46 #include <asm/iseries/it_lp_queue.h>
50 static int mf_initialized
;
53 * This is the structure layout for the Machine Facilites LPAR event
63 u64 state
; /* GetStateOut */
64 u64 ipl_type
; /* GetIplTypeOut, Function02SelectIplTypeIn */
65 u64 ipl_mode
; /* GetIplModeOut, Function02SelectIplModeIn */
66 u64 page
[4]; /* GetSrcHistoryIn */
67 u64 flag
; /* GetAutoIplWhenPrimaryIplsOut,
68 SetAutoIplWhenPrimaryIplsIn,
69 WhiteButtonPowerOffIn,
70 Function08FastPowerOffIn,
71 IsSpcnRackPowerIncompleteOut */
78 } kern
; /* SetKernelImageIn, GetKernelImageIn,
79 SetKernelCmdLineIn, GetKernelCmdLineIn */
80 u32 length_out
; /* GetKernelImageOut, GetKernelCmdLineOut */
86 struct completion com
;
87 struct vsp_cmd_data
*response
;
101 typedef void (*ce_msg_comp_hdlr
)(void *token
, struct ce_msg_data
*vsp_cmd_rsp
);
103 struct ce_msg_comp_data
{
104 ce_msg_comp_hdlr handler
;
111 struct ce_msg_comp_data
*completion
;
114 struct io_mf_lp_event
{
115 struct HvLpEvent hp_lp_event
;
116 u16 subtype_result_code
;
120 struct alloc_data alloc
;
121 struct ce_msg_data ce_msg
;
122 struct vsp_cmd_data vsp_cmd
;
126 #define subtype_data(a, b, c, d) \
127 (((a) << 24) + ((b) << 16) + ((c) << 8) + (d))
130 * All outgoing event traffic is kept on a FIFO queue. The first
131 * pointer points to the one that is outstanding, and all new
132 * requests get stuck on the end. Also, we keep a certain number of
133 * preallocated pending events so that we can operate very early in
134 * the boot up sequence (before kmalloc is ready).
136 struct pending_event
{
137 struct pending_event
*next
;
138 struct io_mf_lp_event event
;
139 MFCompleteHandler hdlr
;
141 unsigned dma_data_length
;
142 unsigned remote_address
;
144 static spinlock_t pending_event_spinlock
;
145 static struct pending_event
*pending_event_head
;
146 static struct pending_event
*pending_event_tail
;
147 static struct pending_event
*pending_event_avail
;
148 #define PENDING_EVENT_PREALLOC_LEN 16
149 static struct pending_event pending_event_prealloc
[PENDING_EVENT_PREALLOC_LEN
];
152 * Put a pending event onto the available queue, so it can get reused.
153 * Attention! You must have the pending_event_spinlock before calling!
155 static void free_pending_event(struct pending_event
*ev
)
158 ev
->next
= pending_event_avail
;
159 pending_event_avail
= ev
;
164 * Enqueue the outbound event onto the stack. If the queue was
165 * empty to begin with, we must also issue it via the Hypervisor
166 * interface. There is a section of code below that will touch
167 * the first stack pointer without the protection of the pending_event_spinlock.
168 * This is OK, because we know that nobody else will be modifying
169 * the first pointer when we do this.
171 static int signal_event(struct pending_event
*ev
)
176 struct pending_event
*ev1
;
179 /* enqueue the event */
182 spin_lock_irqsave(&pending_event_spinlock
, flags
);
183 if (pending_event_head
== NULL
)
184 pending_event_head
= ev
;
187 pending_event_tail
->next
= ev
;
189 pending_event_tail
= ev
;
190 spin_unlock_irqrestore(&pending_event_spinlock
, flags
);
197 /* any DMA data to send beforehand? */
198 if (pending_event_head
->dma_data_length
> 0)
199 HvCallEvent_dmaToSp(pending_event_head
->dma_data
,
200 pending_event_head
->remote_address
,
201 pending_event_head
->dma_data_length
,
202 HvLpDma_Direction_LocalToRemote
);
204 hv_rc
= HvCallEvent_signalLpEvent(
205 &pending_event_head
->event
.hp_lp_event
);
206 if (hv_rc
!= HvLpEvent_Rc_Good
) {
207 printk(KERN_ERR
"mf.c: HvCallEvent_signalLpEvent() "
208 "failed with %d\n", (int)hv_rc
);
210 spin_lock_irqsave(&pending_event_spinlock
, flags
);
211 ev1
= pending_event_head
;
212 pending_event_head
= pending_event_head
->next
;
213 if (pending_event_head
!= NULL
)
215 spin_unlock_irqrestore(&pending_event_spinlock
, flags
);
219 else if (ev1
->hdlr
!= NULL
)
220 (*ev1
->hdlr
)((void *)ev1
->event
.hp_lp_event
.xCorrelationToken
, -EIO
);
222 spin_lock_irqsave(&pending_event_spinlock
, flags
);
223 free_pending_event(ev1
);
224 spin_unlock_irqrestore(&pending_event_spinlock
, flags
);
232 * Allocate a new pending_event structure, and initialize it.
234 static struct pending_event
*new_pending_event(void)
236 struct pending_event
*ev
= NULL
;
237 HvLpIndex primary_lp
= HvLpConfig_getPrimaryLpIndex();
239 struct HvLpEvent
*hev
;
241 spin_lock_irqsave(&pending_event_spinlock
, flags
);
242 if (pending_event_avail
!= NULL
) {
243 ev
= pending_event_avail
;
244 pending_event_avail
= pending_event_avail
->next
;
246 spin_unlock_irqrestore(&pending_event_spinlock
, flags
);
248 ev
= kmalloc(sizeof(struct pending_event
), GFP_ATOMIC
);
250 printk(KERN_ERR
"mf.c: unable to kmalloc %ld bytes\n",
251 sizeof(struct pending_event
));
255 memset(ev
, 0, sizeof(struct pending_event
));
256 hev
= &ev
->event
.hp_lp_event
;
257 hev
->flags
= HV_LP_EVENT_VALID
| HV_LP_EVENT_DO_ACK
| HV_LP_EVENT_INT
;
258 hev
->xType
= HvLpEvent_Type_MachineFac
;
259 hev
->xSourceLp
= HvLpConfig_getLpIndex();
260 hev
->xTargetLp
= primary_lp
;
261 hev
->xSizeMinus1
= sizeof(ev
->event
) - 1;
262 hev
->xRc
= HvLpEvent_Rc_Good
;
263 hev
->xSourceInstanceId
= HvCallEvent_getSourceLpInstanceId(primary_lp
,
264 HvLpEvent_Type_MachineFac
);
265 hev
->xTargetInstanceId
= HvCallEvent_getTargetLpInstanceId(primary_lp
,
266 HvLpEvent_Type_MachineFac
);
271 static int __maybe_unused
272 signal_vsp_instruction(struct vsp_cmd_data
*vsp_cmd
)
274 struct pending_event
*ev
= new_pending_event();
276 struct vsp_rsp_data response
;
281 init_completion(&response
.com
);
282 response
.response
= vsp_cmd
;
283 ev
->event
.hp_lp_event
.xSubtype
= 6;
284 ev
->event
.hp_lp_event
.x
.xSubtypeData
=
285 subtype_data('M', 'F', 'V', 'I');
286 ev
->event
.data
.vsp_cmd
.token
= (u64
)&response
;
287 ev
->event
.data
.vsp_cmd
.cmd
= vsp_cmd
->cmd
;
288 ev
->event
.data
.vsp_cmd
.lp_index
= HvLpConfig_getLpIndex();
289 ev
->event
.data
.vsp_cmd
.result_code
= 0xFF;
290 ev
->event
.data
.vsp_cmd
.reserved
= 0;
291 memcpy(&(ev
->event
.data
.vsp_cmd
.sub_data
),
292 &(vsp_cmd
->sub_data
), sizeof(vsp_cmd
->sub_data
));
295 rc
= signal_event(ev
);
297 wait_for_completion(&response
.com
);
303 * Send a 12-byte CE message to the primary partition VSP object
305 static int signal_ce_msg(char *ce_msg
, struct ce_msg_comp_data
*completion
)
307 struct pending_event
*ev
= new_pending_event();
312 ev
->event
.hp_lp_event
.xSubtype
= 0;
313 ev
->event
.hp_lp_event
.x
.xSubtypeData
=
314 subtype_data('M', 'F', 'C', 'E');
315 memcpy(ev
->event
.data
.ce_msg
.ce_msg
, ce_msg
, 12);
316 ev
->event
.data
.ce_msg
.completion
= completion
;
317 return signal_event(ev
);
321 * Send a 12-byte CE message (with no data) to the primary partition VSP object
323 static int signal_ce_msg_simple(u8 ce_op
, struct ce_msg_comp_data
*completion
)
327 memset(ce_msg
, 0, sizeof(ce_msg
));
329 return signal_ce_msg(ce_msg
, completion
);
333 * Send a 12-byte CE message and DMA data to the primary partition VSP object
335 static int dma_and_signal_ce_msg(char *ce_msg
,
336 struct ce_msg_comp_data
*completion
, void *dma_data
,
337 unsigned dma_data_length
, unsigned remote_address
)
339 struct pending_event
*ev
= new_pending_event();
344 ev
->event
.hp_lp_event
.xSubtype
= 0;
345 ev
->event
.hp_lp_event
.x
.xSubtypeData
=
346 subtype_data('M', 'F', 'C', 'E');
347 memcpy(ev
->event
.data
.ce_msg
.ce_msg
, ce_msg
, 12);
348 ev
->event
.data
.ce_msg
.completion
= completion
;
349 memcpy(ev
->dma_data
, dma_data
, dma_data_length
);
350 ev
->dma_data_length
= dma_data_length
;
351 ev
->remote_address
= remote_address
;
352 return signal_event(ev
);
356 * Initiate a nice (hopefully) shutdown of Linux. We simply are
357 * going to try and send the init process a SIGINT signal. If
358 * this fails (why?), we'll simply force it off in a not-so-nice
361 static int shutdown(void)
363 int rc
= kill_cad_pid(SIGINT
, 1);
366 printk(KERN_ALERT
"mf.c: SIGINT to init failed (%d), "
367 "hard shutdown commencing\n", rc
);
370 printk(KERN_INFO
"mf.c: init has been successfully notified "
371 "to proceed with shutdown\n");
376 * The primary partition VSP object is sending us a new
377 * event flow. Handle it...
379 static void handle_int(struct io_mf_lp_event
*event
)
381 struct ce_msg_data
*ce_msg_data
;
382 struct ce_msg_data
*pce_msg_data
;
384 struct pending_event
*pev
;
386 /* ack the interrupt */
387 event
->hp_lp_event
.xRc
= HvLpEvent_Rc_Good
;
388 HvCallEvent_ackLpEvent(&event
->hp_lp_event
);
390 /* process interrupt */
391 switch (event
->hp_lp_event
.xSubtype
) {
392 case 0: /* CE message */
393 ce_msg_data
= &event
->data
.ce_msg
;
394 switch (ce_msg_data
->ce_msg
[3]) {
395 case 0x5B: /* power control notification */
396 if ((ce_msg_data
->ce_msg
[5] & 0x20) != 0) {
397 printk(KERN_INFO
"mf.c: Commencing partition shutdown\n");
399 signal_ce_msg_simple(0xDB, NULL
);
402 case 0xC0: /* get time */
403 spin_lock_irqsave(&pending_event_spinlock
, flags
);
404 pev
= pending_event_head
;
406 pending_event_head
= pending_event_head
->next
;
407 spin_unlock_irqrestore(&pending_event_spinlock
, flags
);
410 pce_msg_data
= &pev
->event
.data
.ce_msg
;
411 if (pce_msg_data
->ce_msg
[3] != 0x40)
413 if (pce_msg_data
->completion
!= NULL
) {
414 ce_msg_comp_hdlr handler
=
415 pce_msg_data
->completion
->handler
;
416 void *token
= pce_msg_data
->completion
->token
;
419 (*handler
)(token
, ce_msg_data
);
421 spin_lock_irqsave(&pending_event_spinlock
, flags
);
422 free_pending_event(pev
);
423 spin_unlock_irqrestore(&pending_event_spinlock
, flags
);
424 /* send next waiting event */
425 if (pending_event_head
!= NULL
)
430 case 1: /* IT sys shutdown */
431 printk(KERN_INFO
"mf.c: Commencing system shutdown\n");
438 * The primary partition VSP object is acknowledging the receipt
439 * of a flow we sent to them. If there are other flows queued
440 * up, we must send another one now...
442 static void handle_ack(struct io_mf_lp_event
*event
)
445 struct pending_event
*two
= NULL
;
446 unsigned long free_it
= 0;
447 struct ce_msg_data
*ce_msg_data
;
448 struct ce_msg_data
*pce_msg_data
;
449 struct vsp_rsp_data
*rsp
;
451 /* handle current event */
452 if (pending_event_head
== NULL
) {
453 printk(KERN_ERR
"mf.c: stack empty for receiving ack\n");
457 switch (event
->hp_lp_event
.xSubtype
) {
459 ce_msg_data
= &event
->data
.ce_msg
;
460 if (ce_msg_data
->ce_msg
[3] != 0x40) {
464 if (ce_msg_data
->ce_msg
[2] == 0)
467 pce_msg_data
= &pending_event_head
->event
.data
.ce_msg
;
468 if (pce_msg_data
->completion
!= NULL
) {
469 ce_msg_comp_hdlr handler
=
470 pce_msg_data
->completion
->handler
;
471 void *token
= pce_msg_data
->completion
->token
;
474 (*handler
)(token
, ce_msg_data
);
477 case 4: /* allocate */
478 case 5: /* deallocate */
479 if (pending_event_head
->hdlr
!= NULL
)
480 (*pending_event_head
->hdlr
)((void *)event
->hp_lp_event
.xCorrelationToken
, event
->data
.alloc
.count
);
485 rsp
= (struct vsp_rsp_data
*)event
->data
.vsp_cmd
.token
;
487 printk(KERN_ERR
"mf.c: no rsp\n");
490 if (rsp
->response
!= NULL
)
491 memcpy(rsp
->response
, &event
->data
.vsp_cmd
,
492 sizeof(event
->data
.vsp_cmd
));
497 /* remove from queue */
498 spin_lock_irqsave(&pending_event_spinlock
, flags
);
499 if ((pending_event_head
!= NULL
) && (free_it
== 1)) {
500 struct pending_event
*oldHead
= pending_event_head
;
502 pending_event_head
= pending_event_head
->next
;
503 two
= pending_event_head
;
504 free_pending_event(oldHead
);
506 spin_unlock_irqrestore(&pending_event_spinlock
, flags
);
508 /* send next waiting event */
514 * This is the generic event handler we are registering with
515 * the Hypervisor. Ensure the flows are for us, and then
516 * parse it enough to know if it is an interrupt or an
519 static void hv_handler(struct HvLpEvent
*event
)
521 if ((event
!= NULL
) && (event
->xType
== HvLpEvent_Type_MachineFac
)) {
522 if (hvlpevent_is_ack(event
))
523 handle_ack((struct io_mf_lp_event
*)event
);
525 handle_int((struct io_mf_lp_event
*)event
);
527 printk(KERN_ERR
"mf.c: alien event received\n");
531 * Global kernel interface to allocate and seed events into the
534 void mf_allocate_lp_events(HvLpIndex target_lp
, HvLpEvent_Type type
,
535 unsigned size
, unsigned count
, MFCompleteHandler hdlr
,
538 struct pending_event
*ev
= new_pending_event();
544 ev
->event
.hp_lp_event
.xSubtype
= 4;
545 ev
->event
.hp_lp_event
.xCorrelationToken
= (u64
)user_token
;
546 ev
->event
.hp_lp_event
.x
.xSubtypeData
=
547 subtype_data('M', 'F', 'M', 'A');
548 ev
->event
.data
.alloc
.target_lp
= target_lp
;
549 ev
->event
.data
.alloc
.type
= type
;
550 ev
->event
.data
.alloc
.size
= size
;
551 ev
->event
.data
.alloc
.count
= count
;
553 rc
= signal_event(ev
);
555 if ((rc
!= 0) && (hdlr
!= NULL
))
556 (*hdlr
)(user_token
, rc
);
558 EXPORT_SYMBOL(mf_allocate_lp_events
);
561 * Global kernel interface to unseed and deallocate events already in
564 void mf_deallocate_lp_events(HvLpIndex target_lp
, HvLpEvent_Type type
,
565 unsigned count
, MFCompleteHandler hdlr
, void *user_token
)
567 struct pending_event
*ev
= new_pending_event();
573 ev
->event
.hp_lp_event
.xSubtype
= 5;
574 ev
->event
.hp_lp_event
.xCorrelationToken
= (u64
)user_token
;
575 ev
->event
.hp_lp_event
.x
.xSubtypeData
=
576 subtype_data('M', 'F', 'M', 'D');
577 ev
->event
.data
.alloc
.target_lp
= target_lp
;
578 ev
->event
.data
.alloc
.type
= type
;
579 ev
->event
.data
.alloc
.count
= count
;
581 rc
= signal_event(ev
);
583 if ((rc
!= 0) && (hdlr
!= NULL
))
584 (*hdlr
)(user_token
, rc
);
586 EXPORT_SYMBOL(mf_deallocate_lp_events
);
589 * Global kernel interface to tell the VSP object in the primary
590 * partition to power this partition off.
592 void mf_power_off(void)
594 printk(KERN_INFO
"mf.c: Down it goes...\n");
595 signal_ce_msg_simple(0x4d, NULL
);
601 * Global kernel interface to tell the VSP object in the primary
602 * partition to reboot this partition.
604 void mf_reboot(char *cmd
)
606 printk(KERN_INFO
"mf.c: Preparing to bounce...\n");
607 signal_ce_msg_simple(0x4e, NULL
);
613 * Display a single word SRC onto the VSP control panel.
615 void mf_display_src(u32 word
)
619 memset(ce
, 0, sizeof(ce
));
626 signal_ce_msg(ce
, NULL
);
630 * Display a single word SRC of the form "PROGXXXX" on the VSP control panel.
632 static __init
void mf_display_progress_src(u16 value
)
637 memcpy(ce
, "\x00\x00\x04\x4A\x00\x00\x00\x48\x00\x00\x00\x00", 12);
638 memcpy(src
, "\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00"
639 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
640 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
641 "\x00\x00\x00\x00PROGxxxx ",
644 src
[7] = value
& 255;
645 src
[44] = "0123456789ABCDEF"[(value
>> 12) & 15];
646 src
[45] = "0123456789ABCDEF"[(value
>> 8) & 15];
647 src
[46] = "0123456789ABCDEF"[(value
>> 4) & 15];
648 src
[47] = "0123456789ABCDEF"[value
& 15];
649 dma_and_signal_ce_msg(ce
, NULL
, src
, sizeof(src
), 9 * 64 * 1024);
653 * Clear the VSP control panel. Used to "erase" an SRC that was
654 * previously displayed.
656 static void mf_clear_src(void)
658 signal_ce_msg_simple(0x4b, NULL
);
661 void __init
mf_display_progress(u16 value
)
669 mf_display_progress_src(value
);
673 * Initialization code here.
675 void __init
mf_init(void)
679 spin_lock_init(&pending_event_spinlock
);
681 for (i
= 0; i
< PENDING_EVENT_PREALLOC_LEN
; i
++)
682 free_pending_event(&pending_event_prealloc
[i
]);
684 HvLpEvent_registerHandler(HvLpEvent_Type_MachineFac
, &hv_handler
);
686 /* virtual continue ack */
687 signal_ce_msg_simple(0x57, NULL
);
692 printk(KERN_NOTICE
"mf.c: iSeries Linux LPAR Machine Facilities "
696 struct rtc_time_data
{
697 struct completion com
;
698 struct ce_msg_data ce_msg
;
702 static void get_rtc_time_complete(void *token
, struct ce_msg_data
*ce_msg
)
704 struct rtc_time_data
*rtc
= token
;
706 memcpy(&rtc
->ce_msg
, ce_msg
, sizeof(rtc
->ce_msg
));
711 static int mf_set_rtc(struct rtc_time
*tm
)
714 u8 day
, mon
, hour
, min
, sec
, y1
, y2
;
717 year
= 1900 + tm
->tm_year
;
725 mon
= tm
->tm_mon
+ 1;
729 hour
= bin2bcd(hour
);
735 memset(ce_time
, 0, sizeof(ce_time
));
745 return signal_ce_msg(ce_time
, NULL
);
748 static int rtc_set_tm(int rc
, u8
*ce_msg
, struct rtc_time
*tm
)
763 if ((ce_msg
[2] == 0xa9) ||
764 (ce_msg
[2] == 0xaf)) {
765 /* TOD clock is not set */
784 hour
= bcd2bin(hour
);
787 year
= bcd2bin(year
);
803 static int mf_get_rtc(struct rtc_time
*tm
)
805 struct ce_msg_comp_data ce_complete
;
806 struct rtc_time_data rtc_data
;
809 memset(&ce_complete
, 0, sizeof(ce_complete
));
810 memset(&rtc_data
, 0, sizeof(rtc_data
));
811 init_completion(&rtc_data
.com
);
812 ce_complete
.handler
= &get_rtc_time_complete
;
813 ce_complete
.token
= &rtc_data
;
814 rc
= signal_ce_msg_simple(0x40, &ce_complete
);
817 wait_for_completion(&rtc_data
.com
);
818 return rtc_set_tm(rtc_data
.rc
, rtc_data
.ce_msg
.ce_msg
, tm
);
821 struct boot_rtc_time_data
{
823 struct ce_msg_data ce_msg
;
827 static void get_boot_rtc_time_complete(void *token
, struct ce_msg_data
*ce_msg
)
829 struct boot_rtc_time_data
*rtc
= token
;
831 memcpy(&rtc
->ce_msg
, ce_msg
, sizeof(rtc
->ce_msg
));
836 static int mf_get_boot_rtc(struct rtc_time
*tm
)
838 struct ce_msg_comp_data ce_complete
;
839 struct boot_rtc_time_data rtc_data
;
842 memset(&ce_complete
, 0, sizeof(ce_complete
));
843 memset(&rtc_data
, 0, sizeof(rtc_data
));
845 ce_complete
.handler
= &get_boot_rtc_time_complete
;
846 ce_complete
.token
= &rtc_data
;
847 rc
= signal_ce_msg_simple(0x40, &ce_complete
);
850 /* We need to poll here as we are not yet taking interrupts */
851 while (rtc_data
.busy
) {
852 if (hvlpevent_is_pending())
853 process_hvlpevents();
855 return rtc_set_tm(rtc_data
.rc
, rtc_data
.ce_msg
.ce_msg
, tm
);
858 #ifdef CONFIG_PROC_FS
859 static int mf_cmdline_proc_show(struct seq_file
*m
, void *v
)
862 struct vsp_cmd_data vsp_cmd
;
866 /* The HV appears to return no more than 256 bytes of command line */
867 page
= kmalloc(256, GFP_KERNEL
);
871 dma_addr
= iseries_hv_map(page
, 256, DMA_FROM_DEVICE
);
872 if (dma_addr
== DMA_ERROR_CODE
) {
876 memset(page
, 0, 256);
877 memset(&vsp_cmd
, 0, sizeof(vsp_cmd
));
879 vsp_cmd
.sub_data
.kern
.token
= dma_addr
;
880 vsp_cmd
.sub_data
.kern
.address_type
= HvLpDma_AddressType_TceIndex
;
881 vsp_cmd
.sub_data
.kern
.side
= (u64
)m
->private;
882 vsp_cmd
.sub_data
.kern
.length
= 256;
884 rc
= signal_vsp_instruction(&vsp_cmd
);
885 iseries_hv_unmap(dma_addr
, 256, DMA_FROM_DEVICE
);
890 if (vsp_cmd
.result_code
!= 0) {
895 while (p
- page
< 256) {
896 if (*p
== '\0' || *p
== '\n') {
903 seq_write(m
, page
, p
- page
);
908 static int mf_cmdline_proc_open(struct inode
*inode
, struct file
*file
)
910 return single_open(file
, mf_cmdline_proc_show
, PDE(inode
)->data
);
914 static int mf_getVmlinuxChunk(char *buffer
, int *size
, int offset
, u64 side
)
916 struct vsp_cmd_data vsp_cmd
;
921 dma_addr
= iseries_hv_map(buffer
, len
, DMA_FROM_DEVICE
);
922 memset(buffer
, 0, len
);
923 memset(&vsp_cmd
, 0, sizeof(vsp_cmd
));
925 vsp_cmd
.sub_data
.kern
.token
= dma_addr
;
926 vsp_cmd
.sub_data
.kern
.address_type
= HvLpDma_AddressType_TceIndex
;
927 vsp_cmd
.sub_data
.kern
.side
= side
;
928 vsp_cmd
.sub_data
.kern
.offset
= offset
;
929 vsp_cmd
.sub_data
.kern
.length
= len
;
931 rc
= signal_vsp_instruction(&vsp_cmd
);
933 if (vsp_cmd
.result_code
== 0)
934 *size
= vsp_cmd
.sub_data
.length_out
;
939 iseries_hv_unmap(dma_addr
, len
, DMA_FROM_DEVICE
);
944 static int proc_mf_dump_vmlinux(char *page
, char **start
, off_t off
,
945 int count
, int *eof
, void *data
)
947 int sizeToGet
= count
;
949 if (!capable(CAP_SYS_ADMIN
))
952 if (mf_getVmlinuxChunk(page
, &sizeToGet
, off
, (u64
)data
) == 0) {
953 if (sizeToGet
!= 0) {
965 static int mf_side_proc_show(struct seq_file
*m
, void *v
)
967 char mf_current_side
= ' ';
968 struct vsp_cmd_data vsp_cmd
;
970 memset(&vsp_cmd
, 0, sizeof(vsp_cmd
));
972 vsp_cmd
.sub_data
.ipl_type
= 0;
975 if (signal_vsp_instruction(&vsp_cmd
) == 0) {
976 if (vsp_cmd
.result_code
== 0) {
977 switch (vsp_cmd
.sub_data
.ipl_type
) {
978 case 0: mf_current_side
= 'A';
980 case 1: mf_current_side
= 'B';
982 case 2: mf_current_side
= 'C';
984 default: mf_current_side
= 'D';
990 seq_printf(m
, "%c\n", mf_current_side
);
994 static int mf_side_proc_open(struct inode
*inode
, struct file
*file
)
996 return single_open(file
, mf_side_proc_show
, NULL
);
999 static ssize_t
mf_side_proc_write(struct file
*file
, const char __user
*buffer
,
1000 size_t count
, loff_t
*pos
)
1004 struct vsp_cmd_data vsp_cmd
;
1006 if (!capable(CAP_SYS_ADMIN
))
1012 if (get_user(side
, buffer
))
1016 case 'A': newSide
= 0;
1018 case 'B': newSide
= 1;
1020 case 'C': newSide
= 2;
1022 case 'D': newSide
= 3;
1025 printk(KERN_ERR
"mf_proc.c: proc_mf_change_side: invalid side\n");
1029 memset(&vsp_cmd
, 0, sizeof(vsp_cmd
));
1030 vsp_cmd
.sub_data
.ipl_type
= newSide
;
1033 (void)signal_vsp_instruction(&vsp_cmd
);
1038 static const struct file_operations mf_side_proc_fops
= {
1039 .owner
= THIS_MODULE
,
1040 .open
= mf_side_proc_open
,
1042 .llseek
= seq_lseek
,
1043 .release
= single_release
,
1044 .write
= mf_side_proc_write
,
1048 static void mf_getSrcHistory(char *buffer
, int size
)
1050 struct IplTypeReturnStuff return_stuff
;
1051 struct pending_event
*ev
= new_pending_event();
1055 pages
[0] = kmalloc(4096, GFP_ATOMIC
);
1056 pages
[1] = kmalloc(4096, GFP_ATOMIC
);
1057 pages
[2] = kmalloc(4096, GFP_ATOMIC
);
1058 pages
[3] = kmalloc(4096, GFP_ATOMIC
);
1059 if ((ev
== NULL
) || (pages
[0] == NULL
) || (pages
[1] == NULL
)
1060 || (pages
[2] == NULL
) || (pages
[3] == NULL
))
1063 return_stuff
.xType
= 0;
1064 return_stuff
.xRc
= 0;
1065 return_stuff
.xDone
= 0;
1066 ev
->event
.hp_lp_event
.xSubtype
= 6;
1067 ev
->event
.hp_lp_event
.x
.xSubtypeData
=
1068 subtype_data('M', 'F', 'V', 'I');
1069 ev
->event
.data
.vsp_cmd
.xEvent
= &return_stuff
;
1070 ev
->event
.data
.vsp_cmd
.cmd
= 4;
1071 ev
->event
.data
.vsp_cmd
.lp_index
= HvLpConfig_getLpIndex();
1072 ev
->event
.data
.vsp_cmd
.result_code
= 0xFF;
1073 ev
->event
.data
.vsp_cmd
.reserved
= 0;
1074 ev
->event
.data
.vsp_cmd
.sub_data
.page
[0] = iseries_hv_addr(pages
[0]);
1075 ev
->event
.data
.vsp_cmd
.sub_data
.page
[1] = iseries_hv_addr(pages
[1]);
1076 ev
->event
.data
.vsp_cmd
.sub_data
.page
[2] = iseries_hv_addr(pages
[2]);
1077 ev
->event
.data
.vsp_cmd
.sub_data
.page
[3] = iseries_hv_addr(pages
[3]);
1079 if (signal_event(ev
) != 0)
1082 while (return_stuff
.xDone
!= 1)
1084 if (return_stuff
.xRc
== 0)
1085 memcpy(buffer
, pages
[0], size
);
1093 static int mf_src_proc_show(struct seq_file
*m
, void *v
)
1098 mf_getSrcHistory(page
, count
);
1107 *start
= page
+ off
;
1114 static int mf_src_proc_open(struct inode
*inode
, struct file
*file
)
1116 return single_open(file
, mf_src_proc_show
, NULL
);
1119 static ssize_t
mf_src_proc_write(struct file
*file
, const char __user
*buffer
,
1120 size_t count
, loff_t
*pos
)
1124 if (!capable(CAP_SYS_ADMIN
))
1127 if ((count
< 4) && (count
!= 1)) {
1128 printk(KERN_ERR
"mf_proc: invalid src\n");
1132 if (count
> (sizeof(stkbuf
) - 1))
1133 count
= sizeof(stkbuf
) - 1;
1134 if (copy_from_user(stkbuf
, buffer
, count
))
1137 if ((count
== 1) && (*stkbuf
== '\0'))
1140 mf_display_src(*(u32
*)stkbuf
);
1145 static const struct file_operations mf_src_proc_fops
= {
1146 .owner
= THIS_MODULE
,
1147 .open
= mf_src_proc_open
,
1149 .llseek
= seq_lseek
,
1150 .release
= single_release
,
1151 .write
= mf_src_proc_write
,
1154 static ssize_t
mf_cmdline_proc_write(struct file
*file
, const char __user
*buffer
,
1155 size_t count
, loff_t
*pos
)
1157 void *data
= PDE(file
->f_path
.dentry
->d_inode
)->data
;
1158 struct vsp_cmd_data vsp_cmd
;
1159 dma_addr_t dma_addr
;
1163 if (!capable(CAP_SYS_ADMIN
))
1167 page
= iseries_hv_alloc(count
, &dma_addr
, GFP_ATOMIC
);
1173 if (copy_from_user(page
, buffer
, count
))
1176 memset(&vsp_cmd
, 0, sizeof(vsp_cmd
));
1178 vsp_cmd
.sub_data
.kern
.token
= dma_addr
;
1179 vsp_cmd
.sub_data
.kern
.address_type
= HvLpDma_AddressType_TceIndex
;
1180 vsp_cmd
.sub_data
.kern
.side
= (u64
)data
;
1181 vsp_cmd
.sub_data
.kern
.length
= count
;
1183 (void)signal_vsp_instruction(&vsp_cmd
);
1187 iseries_hv_free(count
, page
, dma_addr
);
1192 static const struct file_operations mf_cmdline_proc_fops
= {
1193 .owner
= THIS_MODULE
,
1194 .open
= mf_cmdline_proc_open
,
1196 .llseek
= seq_lseek
,
1197 .release
= single_release
,
1198 .write
= mf_cmdline_proc_write
,
1201 static ssize_t
proc_mf_change_vmlinux(struct file
*file
,
1202 const char __user
*buf
,
1203 size_t count
, loff_t
*ppos
)
1205 struct proc_dir_entry
*dp
= PDE(file
->f_path
.dentry
->d_inode
);
1207 dma_addr_t dma_addr
;
1209 struct vsp_cmd_data vsp_cmd
;
1212 if (!capable(CAP_SYS_ADMIN
))
1216 page
= iseries_hv_alloc(count
, &dma_addr
, GFP_ATOMIC
);
1219 printk(KERN_ERR
"mf.c: couldn't allocate memory to set vmlinux chunk\n");
1223 if (copy_from_user(page
, buf
, count
))
1226 memset(&vsp_cmd
, 0, sizeof(vsp_cmd
));
1228 vsp_cmd
.sub_data
.kern
.token
= dma_addr
;
1229 vsp_cmd
.sub_data
.kern
.address_type
= HvLpDma_AddressType_TceIndex
;
1230 vsp_cmd
.sub_data
.kern
.side
= (u64
)dp
->data
;
1231 vsp_cmd
.sub_data
.kern
.offset
= *ppos
;
1232 vsp_cmd
.sub_data
.kern
.length
= count
;
1234 rc
= signal_vsp_instruction(&vsp_cmd
);
1238 if (vsp_cmd
.result_code
!= 0)
1244 iseries_hv_free(count
, page
, dma_addr
);
1249 static const struct file_operations proc_vmlinux_operations
= {
1250 .write
= proc_mf_change_vmlinux
,
1253 static int __init
mf_proc_init(void)
1255 struct proc_dir_entry
*mf_proc_root
;
1256 struct proc_dir_entry
*ent
;
1257 struct proc_dir_entry
*mf
;
1261 if (!firmware_has_feature(FW_FEATURE_ISERIES
))
1264 mf_proc_root
= proc_mkdir("iSeries/mf", NULL
);
1269 for (i
= 0; i
< 4; i
++) {
1271 mf
= proc_mkdir(name
, mf_proc_root
);
1275 ent
= proc_create_data("cmdline", S_IRUSR
|S_IWUSR
, mf
,
1276 &mf_cmdline_proc_fops
, (void *)(long)i
);
1280 if (i
== 3) /* no vmlinux entry for 'D' */
1283 ent
= proc_create_data("vmlinux", S_IFREG
|S_IWUSR
, mf
,
1284 &proc_vmlinux_operations
,
1290 ent
= proc_create("side", S_IFREG
|S_IRUSR
|S_IWUSR
, mf_proc_root
,
1291 &mf_side_proc_fops
);
1295 ent
= proc_create("src", S_IFREG
|S_IRUSR
|S_IWUSR
, mf_proc_root
,
1303 __initcall(mf_proc_init
);
1305 #endif /* CONFIG_PROC_FS */
1308 * Get the RTC from the virtual service processor
1309 * This requires flowing LpEvents to the primary partition
1311 void iSeries_get_rtc_time(struct rtc_time
*rtc_tm
)
1318 * Set the RTC in the virtual service processor
1319 * This requires flowing LpEvents to the primary partition
1321 int iSeries_set_rtc_time(struct rtc_time
*tm
)
1327 unsigned long iSeries_get_boot_time(void)
1331 mf_get_boot_rtc(&tm
);
1332 return mktime(tm
.tm_year
+ 1900, tm
.tm_mon
, tm
.tm_mday
,
1333 tm
.tm_hour
, tm
.tm_min
, tm
.tm_sec
);