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/proc_fs.h>
34 #include <linux/dma-mapping.h>
35 #include <linux/bcd.h>
36 #include <linux/rtc.h>
37 #include <linux/slab.h>
40 #include <asm/uaccess.h>
42 #include <asm/abs_addr.h>
43 #include <asm/firmware.h>
44 #include <asm/iseries/mf.h>
45 #include <asm/iseries/hv_lp_config.h>
46 #include <asm/iseries/hv_lp_event.h>
47 #include <asm/iseries/it_lp_queue.h>
51 static int mf_initialized
;
54 * This is the structure layout for the Machine Facilites LPAR event
64 u64 state
; /* GetStateOut */
65 u64 ipl_type
; /* GetIplTypeOut, Function02SelectIplTypeIn */
66 u64 ipl_mode
; /* GetIplModeOut, Function02SelectIplModeIn */
67 u64 page
[4]; /* GetSrcHistoryIn */
68 u64 flag
; /* GetAutoIplWhenPrimaryIplsOut,
69 SetAutoIplWhenPrimaryIplsIn,
70 WhiteButtonPowerOffIn,
71 Function08FastPowerOffIn,
72 IsSpcnRackPowerIncompleteOut */
79 } kern
; /* SetKernelImageIn, GetKernelImageIn,
80 SetKernelCmdLineIn, GetKernelCmdLineIn */
81 u32 length_out
; /* GetKernelImageOut, GetKernelCmdLineOut */
87 struct completion com
;
88 struct vsp_cmd_data
*response
;
102 typedef void (*ce_msg_comp_hdlr
)(void *token
, struct ce_msg_data
*vsp_cmd_rsp
);
104 struct ce_msg_comp_data
{
105 ce_msg_comp_hdlr handler
;
112 struct ce_msg_comp_data
*completion
;
115 struct io_mf_lp_event
{
116 struct HvLpEvent hp_lp_event
;
117 u16 subtype_result_code
;
121 struct alloc_data alloc
;
122 struct ce_msg_data ce_msg
;
123 struct vsp_cmd_data vsp_cmd
;
127 #define subtype_data(a, b, c, d) \
128 (((a) << 24) + ((b) << 16) + ((c) << 8) + (d))
131 * All outgoing event traffic is kept on a FIFO queue. The first
132 * pointer points to the one that is outstanding, and all new
133 * requests get stuck on the end. Also, we keep a certain number of
134 * preallocated pending events so that we can operate very early in
135 * the boot up sequence (before kmalloc is ready).
137 struct pending_event
{
138 struct pending_event
*next
;
139 struct io_mf_lp_event event
;
140 MFCompleteHandler hdlr
;
142 unsigned dma_data_length
;
143 unsigned remote_address
;
145 static spinlock_t pending_event_spinlock
;
146 static struct pending_event
*pending_event_head
;
147 static struct pending_event
*pending_event_tail
;
148 static struct pending_event
*pending_event_avail
;
149 #define PENDING_EVENT_PREALLOC_LEN 16
150 static struct pending_event pending_event_prealloc
[PENDING_EVENT_PREALLOC_LEN
];
153 * Put a pending event onto the available queue, so it can get reused.
154 * Attention! You must have the pending_event_spinlock before calling!
156 static void free_pending_event(struct pending_event
*ev
)
159 ev
->next
= pending_event_avail
;
160 pending_event_avail
= ev
;
165 * Enqueue the outbound event onto the stack. If the queue was
166 * empty to begin with, we must also issue it via the Hypervisor
167 * interface. There is a section of code below that will touch
168 * the first stack pointer without the protection of the pending_event_spinlock.
169 * This is OK, because we know that nobody else will be modifying
170 * the first pointer when we do this.
172 static int signal_event(struct pending_event
*ev
)
177 struct pending_event
*ev1
;
180 /* enqueue the event */
183 spin_lock_irqsave(&pending_event_spinlock
, flags
);
184 if (pending_event_head
== NULL
)
185 pending_event_head
= ev
;
188 pending_event_tail
->next
= ev
;
190 pending_event_tail
= ev
;
191 spin_unlock_irqrestore(&pending_event_spinlock
, flags
);
198 /* any DMA data to send beforehand? */
199 if (pending_event_head
->dma_data_length
> 0)
200 HvCallEvent_dmaToSp(pending_event_head
->dma_data
,
201 pending_event_head
->remote_address
,
202 pending_event_head
->dma_data_length
,
203 HvLpDma_Direction_LocalToRemote
);
205 hv_rc
= HvCallEvent_signalLpEvent(
206 &pending_event_head
->event
.hp_lp_event
);
207 if (hv_rc
!= HvLpEvent_Rc_Good
) {
208 printk(KERN_ERR
"mf.c: HvCallEvent_signalLpEvent() "
209 "failed with %d\n", (int)hv_rc
);
211 spin_lock_irqsave(&pending_event_spinlock
, flags
);
212 ev1
= pending_event_head
;
213 pending_event_head
= pending_event_head
->next
;
214 if (pending_event_head
!= NULL
)
216 spin_unlock_irqrestore(&pending_event_spinlock
, flags
);
220 else if (ev1
->hdlr
!= NULL
)
221 (*ev1
->hdlr
)((void *)ev1
->event
.hp_lp_event
.xCorrelationToken
, -EIO
);
223 spin_lock_irqsave(&pending_event_spinlock
, flags
);
224 free_pending_event(ev1
);
225 spin_unlock_irqrestore(&pending_event_spinlock
, flags
);
233 * Allocate a new pending_event structure, and initialize it.
235 static struct pending_event
*new_pending_event(void)
237 struct pending_event
*ev
= NULL
;
238 HvLpIndex primary_lp
= HvLpConfig_getPrimaryLpIndex();
240 struct HvLpEvent
*hev
;
242 spin_lock_irqsave(&pending_event_spinlock
, flags
);
243 if (pending_event_avail
!= NULL
) {
244 ev
= pending_event_avail
;
245 pending_event_avail
= pending_event_avail
->next
;
247 spin_unlock_irqrestore(&pending_event_spinlock
, flags
);
249 ev
= kmalloc(sizeof(struct pending_event
), GFP_ATOMIC
);
251 printk(KERN_ERR
"mf.c: unable to kmalloc %ld bytes\n",
252 sizeof(struct pending_event
));
256 memset(ev
, 0, sizeof(struct pending_event
));
257 hev
= &ev
->event
.hp_lp_event
;
258 hev
->flags
= HV_LP_EVENT_VALID
| HV_LP_EVENT_DO_ACK
| HV_LP_EVENT_INT
;
259 hev
->xType
= HvLpEvent_Type_MachineFac
;
260 hev
->xSourceLp
= HvLpConfig_getLpIndex();
261 hev
->xTargetLp
= primary_lp
;
262 hev
->xSizeMinus1
= sizeof(ev
->event
) - 1;
263 hev
->xRc
= HvLpEvent_Rc_Good
;
264 hev
->xSourceInstanceId
= HvCallEvent_getSourceLpInstanceId(primary_lp
,
265 HvLpEvent_Type_MachineFac
);
266 hev
->xTargetInstanceId
= HvCallEvent_getTargetLpInstanceId(primary_lp
,
267 HvLpEvent_Type_MachineFac
);
272 static int __maybe_unused
273 signal_vsp_instruction(struct vsp_cmd_data
*vsp_cmd
)
275 struct pending_event
*ev
= new_pending_event();
277 struct vsp_rsp_data response
;
282 init_completion(&response
.com
);
283 response
.response
= vsp_cmd
;
284 ev
->event
.hp_lp_event
.xSubtype
= 6;
285 ev
->event
.hp_lp_event
.x
.xSubtypeData
=
286 subtype_data('M', 'F', 'V', 'I');
287 ev
->event
.data
.vsp_cmd
.token
= (u64
)&response
;
288 ev
->event
.data
.vsp_cmd
.cmd
= vsp_cmd
->cmd
;
289 ev
->event
.data
.vsp_cmd
.lp_index
= HvLpConfig_getLpIndex();
290 ev
->event
.data
.vsp_cmd
.result_code
= 0xFF;
291 ev
->event
.data
.vsp_cmd
.reserved
= 0;
292 memcpy(&(ev
->event
.data
.vsp_cmd
.sub_data
),
293 &(vsp_cmd
->sub_data
), sizeof(vsp_cmd
->sub_data
));
296 rc
= signal_event(ev
);
298 wait_for_completion(&response
.com
);
304 * Send a 12-byte CE message to the primary partition VSP object
306 static int signal_ce_msg(char *ce_msg
, struct ce_msg_comp_data
*completion
)
308 struct pending_event
*ev
= new_pending_event();
313 ev
->event
.hp_lp_event
.xSubtype
= 0;
314 ev
->event
.hp_lp_event
.x
.xSubtypeData
=
315 subtype_data('M', 'F', 'C', 'E');
316 memcpy(ev
->event
.data
.ce_msg
.ce_msg
, ce_msg
, 12);
317 ev
->event
.data
.ce_msg
.completion
= completion
;
318 return signal_event(ev
);
322 * Send a 12-byte CE message (with no data) to the primary partition VSP object
324 static int signal_ce_msg_simple(u8 ce_op
, struct ce_msg_comp_data
*completion
)
328 memset(ce_msg
, 0, sizeof(ce_msg
));
330 return signal_ce_msg(ce_msg
, completion
);
334 * Send a 12-byte CE message and DMA data to the primary partition VSP object
336 static int dma_and_signal_ce_msg(char *ce_msg
,
337 struct ce_msg_comp_data
*completion
, void *dma_data
,
338 unsigned dma_data_length
, unsigned remote_address
)
340 struct pending_event
*ev
= new_pending_event();
345 ev
->event
.hp_lp_event
.xSubtype
= 0;
346 ev
->event
.hp_lp_event
.x
.xSubtypeData
=
347 subtype_data('M', 'F', 'C', 'E');
348 memcpy(ev
->event
.data
.ce_msg
.ce_msg
, ce_msg
, 12);
349 ev
->event
.data
.ce_msg
.completion
= completion
;
350 memcpy(ev
->dma_data
, dma_data
, dma_data_length
);
351 ev
->dma_data_length
= dma_data_length
;
352 ev
->remote_address
= remote_address
;
353 return signal_event(ev
);
357 * Initiate a nice (hopefully) shutdown of Linux. We simply are
358 * going to try and send the init process a SIGINT signal. If
359 * this fails (why?), we'll simply force it off in a not-so-nice
362 static int shutdown(void)
364 int rc
= kill_cad_pid(SIGINT
, 1);
367 printk(KERN_ALERT
"mf.c: SIGINT to init failed (%d), "
368 "hard shutdown commencing\n", rc
);
371 printk(KERN_INFO
"mf.c: init has been successfully notified "
372 "to proceed with shutdown\n");
377 * The primary partition VSP object is sending us a new
378 * event flow. Handle it...
380 static void handle_int(struct io_mf_lp_event
*event
)
382 struct ce_msg_data
*ce_msg_data
;
383 struct ce_msg_data
*pce_msg_data
;
385 struct pending_event
*pev
;
387 /* ack the interrupt */
388 event
->hp_lp_event
.xRc
= HvLpEvent_Rc_Good
;
389 HvCallEvent_ackLpEvent(&event
->hp_lp_event
);
391 /* process interrupt */
392 switch (event
->hp_lp_event
.xSubtype
) {
393 case 0: /* CE message */
394 ce_msg_data
= &event
->data
.ce_msg
;
395 switch (ce_msg_data
->ce_msg
[3]) {
396 case 0x5B: /* power control notification */
397 if ((ce_msg_data
->ce_msg
[5] & 0x20) != 0) {
398 printk(KERN_INFO
"mf.c: Commencing partition shutdown\n");
400 signal_ce_msg_simple(0xDB, NULL
);
403 case 0xC0: /* get time */
404 spin_lock_irqsave(&pending_event_spinlock
, flags
);
405 pev
= pending_event_head
;
407 pending_event_head
= pending_event_head
->next
;
408 spin_unlock_irqrestore(&pending_event_spinlock
, flags
);
411 pce_msg_data
= &pev
->event
.data
.ce_msg
;
412 if (pce_msg_data
->ce_msg
[3] != 0x40)
414 if (pce_msg_data
->completion
!= NULL
) {
415 ce_msg_comp_hdlr handler
=
416 pce_msg_data
->completion
->handler
;
417 void *token
= pce_msg_data
->completion
->token
;
420 (*handler
)(token
, ce_msg_data
);
422 spin_lock_irqsave(&pending_event_spinlock
, flags
);
423 free_pending_event(pev
);
424 spin_unlock_irqrestore(&pending_event_spinlock
, flags
);
425 /* send next waiting event */
426 if (pending_event_head
!= NULL
)
431 case 1: /* IT sys shutdown */
432 printk(KERN_INFO
"mf.c: Commencing system shutdown\n");
439 * The primary partition VSP object is acknowledging the receipt
440 * of a flow we sent to them. If there are other flows queued
441 * up, we must send another one now...
443 static void handle_ack(struct io_mf_lp_event
*event
)
446 struct pending_event
*two
= NULL
;
447 unsigned long free_it
= 0;
448 struct ce_msg_data
*ce_msg_data
;
449 struct ce_msg_data
*pce_msg_data
;
450 struct vsp_rsp_data
*rsp
;
452 /* handle current event */
453 if (pending_event_head
== NULL
) {
454 printk(KERN_ERR
"mf.c: stack empty for receiving ack\n");
458 switch (event
->hp_lp_event
.xSubtype
) {
460 ce_msg_data
= &event
->data
.ce_msg
;
461 if (ce_msg_data
->ce_msg
[3] != 0x40) {
465 if (ce_msg_data
->ce_msg
[2] == 0)
468 pce_msg_data
= &pending_event_head
->event
.data
.ce_msg
;
469 if (pce_msg_data
->completion
!= NULL
) {
470 ce_msg_comp_hdlr handler
=
471 pce_msg_data
->completion
->handler
;
472 void *token
= pce_msg_data
->completion
->token
;
475 (*handler
)(token
, ce_msg_data
);
478 case 4: /* allocate */
479 case 5: /* deallocate */
480 if (pending_event_head
->hdlr
!= NULL
)
481 (*pending_event_head
->hdlr
)((void *)event
->hp_lp_event
.xCorrelationToken
, event
->data
.alloc
.count
);
486 rsp
= (struct vsp_rsp_data
*)event
->data
.vsp_cmd
.token
;
488 printk(KERN_ERR
"mf.c: no rsp\n");
491 if (rsp
->response
!= NULL
)
492 memcpy(rsp
->response
, &event
->data
.vsp_cmd
,
493 sizeof(event
->data
.vsp_cmd
));
498 /* remove from queue */
499 spin_lock_irqsave(&pending_event_spinlock
, flags
);
500 if ((pending_event_head
!= NULL
) && (free_it
== 1)) {
501 struct pending_event
*oldHead
= pending_event_head
;
503 pending_event_head
= pending_event_head
->next
;
504 two
= pending_event_head
;
505 free_pending_event(oldHead
);
507 spin_unlock_irqrestore(&pending_event_spinlock
, flags
);
509 /* send next waiting event */
515 * This is the generic event handler we are registering with
516 * the Hypervisor. Ensure the flows are for us, and then
517 * parse it enough to know if it is an interrupt or an
520 static void hv_handler(struct HvLpEvent
*event
)
522 if ((event
!= NULL
) && (event
->xType
== HvLpEvent_Type_MachineFac
)) {
523 if (hvlpevent_is_ack(event
))
524 handle_ack((struct io_mf_lp_event
*)event
);
526 handle_int((struct io_mf_lp_event
*)event
);
528 printk(KERN_ERR
"mf.c: alien event received\n");
532 * Global kernel interface to allocate and seed events into the
535 void mf_allocate_lp_events(HvLpIndex target_lp
, HvLpEvent_Type type
,
536 unsigned size
, unsigned count
, MFCompleteHandler hdlr
,
539 struct pending_event
*ev
= new_pending_event();
545 ev
->event
.hp_lp_event
.xSubtype
= 4;
546 ev
->event
.hp_lp_event
.xCorrelationToken
= (u64
)user_token
;
547 ev
->event
.hp_lp_event
.x
.xSubtypeData
=
548 subtype_data('M', 'F', 'M', 'A');
549 ev
->event
.data
.alloc
.target_lp
= target_lp
;
550 ev
->event
.data
.alloc
.type
= type
;
551 ev
->event
.data
.alloc
.size
= size
;
552 ev
->event
.data
.alloc
.count
= count
;
554 rc
= signal_event(ev
);
556 if ((rc
!= 0) && (hdlr
!= NULL
))
557 (*hdlr
)(user_token
, rc
);
559 EXPORT_SYMBOL(mf_allocate_lp_events
);
562 * Global kernel interface to unseed and deallocate events already in
565 void mf_deallocate_lp_events(HvLpIndex target_lp
, HvLpEvent_Type type
,
566 unsigned count
, MFCompleteHandler hdlr
, void *user_token
)
568 struct pending_event
*ev
= new_pending_event();
574 ev
->event
.hp_lp_event
.xSubtype
= 5;
575 ev
->event
.hp_lp_event
.xCorrelationToken
= (u64
)user_token
;
576 ev
->event
.hp_lp_event
.x
.xSubtypeData
=
577 subtype_data('M', 'F', 'M', 'D');
578 ev
->event
.data
.alloc
.target_lp
= target_lp
;
579 ev
->event
.data
.alloc
.type
= type
;
580 ev
->event
.data
.alloc
.count
= count
;
582 rc
= signal_event(ev
);
584 if ((rc
!= 0) && (hdlr
!= NULL
))
585 (*hdlr
)(user_token
, rc
);
587 EXPORT_SYMBOL(mf_deallocate_lp_events
);
590 * Global kernel interface to tell the VSP object in the primary
591 * partition to power this partition off.
593 void mf_power_off(void)
595 printk(KERN_INFO
"mf.c: Down it goes...\n");
596 signal_ce_msg_simple(0x4d, NULL
);
602 * Global kernel interface to tell the VSP object in the primary
603 * partition to reboot this partition.
605 void mf_reboot(char *cmd
)
607 printk(KERN_INFO
"mf.c: Preparing to bounce...\n");
608 signal_ce_msg_simple(0x4e, NULL
);
614 * Display a single word SRC onto the VSP control panel.
616 void mf_display_src(u32 word
)
620 memset(ce
, 0, sizeof(ce
));
627 signal_ce_msg(ce
, NULL
);
631 * Display a single word SRC of the form "PROGXXXX" on the VSP control panel.
633 static __init
void mf_display_progress_src(u16 value
)
638 memcpy(ce
, "\x00\x00\x04\x4A\x00\x00\x00\x48\x00\x00\x00\x00", 12);
639 memcpy(src
, "\x01\x00\x00\x01\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\x00\x00\x00\x00\x00\x00\x00\x00\x00"
642 "\x00\x00\x00\x00PROGxxxx ",
645 src
[7] = value
& 255;
646 src
[44] = "0123456789ABCDEF"[(value
>> 12) & 15];
647 src
[45] = "0123456789ABCDEF"[(value
>> 8) & 15];
648 src
[46] = "0123456789ABCDEF"[(value
>> 4) & 15];
649 src
[47] = "0123456789ABCDEF"[value
& 15];
650 dma_and_signal_ce_msg(ce
, NULL
, src
, sizeof(src
), 9 * 64 * 1024);
654 * Clear the VSP control panel. Used to "erase" an SRC that was
655 * previously displayed.
657 static void mf_clear_src(void)
659 signal_ce_msg_simple(0x4b, NULL
);
662 void __init
mf_display_progress(u16 value
)
670 mf_display_progress_src(value
);
674 * Initialization code here.
676 void __init
mf_init(void)
680 spin_lock_init(&pending_event_spinlock
);
682 for (i
= 0; i
< PENDING_EVENT_PREALLOC_LEN
; i
++)
683 free_pending_event(&pending_event_prealloc
[i
]);
685 HvLpEvent_registerHandler(HvLpEvent_Type_MachineFac
, &hv_handler
);
687 /* virtual continue ack */
688 signal_ce_msg_simple(0x57, NULL
);
693 printk(KERN_NOTICE
"mf.c: iSeries Linux LPAR Machine Facilities "
697 struct rtc_time_data
{
698 struct completion com
;
699 struct ce_msg_data ce_msg
;
703 static void get_rtc_time_complete(void *token
, struct ce_msg_data
*ce_msg
)
705 struct rtc_time_data
*rtc
= token
;
707 memcpy(&rtc
->ce_msg
, ce_msg
, sizeof(rtc
->ce_msg
));
712 static int mf_set_rtc(struct rtc_time
*tm
)
715 u8 day
, mon
, hour
, min
, sec
, y1
, y2
;
718 year
= 1900 + tm
->tm_year
;
726 mon
= tm
->tm_mon
+ 1;
730 hour
= bin2bcd(hour
);
736 memset(ce_time
, 0, sizeof(ce_time
));
746 return signal_ce_msg(ce_time
, NULL
);
749 static int rtc_set_tm(int rc
, u8
*ce_msg
, struct rtc_time
*tm
)
764 if ((ce_msg
[2] == 0xa9) ||
765 (ce_msg
[2] == 0xaf)) {
766 /* TOD clock is not set */
785 hour
= bcd2bin(hour
);
788 year
= bcd2bin(year
);
804 static int mf_get_rtc(struct rtc_time
*tm
)
806 struct ce_msg_comp_data ce_complete
;
807 struct rtc_time_data rtc_data
;
810 memset(&ce_complete
, 0, sizeof(ce_complete
));
811 memset(&rtc_data
, 0, sizeof(rtc_data
));
812 init_completion(&rtc_data
.com
);
813 ce_complete
.handler
= &get_rtc_time_complete
;
814 ce_complete
.token
= &rtc_data
;
815 rc
= signal_ce_msg_simple(0x40, &ce_complete
);
818 wait_for_completion(&rtc_data
.com
);
819 return rtc_set_tm(rtc_data
.rc
, rtc_data
.ce_msg
.ce_msg
, tm
);
822 struct boot_rtc_time_data
{
824 struct ce_msg_data ce_msg
;
828 static void get_boot_rtc_time_complete(void *token
, struct ce_msg_data
*ce_msg
)
830 struct boot_rtc_time_data
*rtc
= token
;
832 memcpy(&rtc
->ce_msg
, ce_msg
, sizeof(rtc
->ce_msg
));
837 static int mf_get_boot_rtc(struct rtc_time
*tm
)
839 struct ce_msg_comp_data ce_complete
;
840 struct boot_rtc_time_data rtc_data
;
843 memset(&ce_complete
, 0, sizeof(ce_complete
));
844 memset(&rtc_data
, 0, sizeof(rtc_data
));
846 ce_complete
.handler
= &get_boot_rtc_time_complete
;
847 ce_complete
.token
= &rtc_data
;
848 rc
= signal_ce_msg_simple(0x40, &ce_complete
);
851 /* We need to poll here as we are not yet taking interrupts */
852 while (rtc_data
.busy
) {
853 if (hvlpevent_is_pending())
854 process_hvlpevents();
856 return rtc_set_tm(rtc_data
.rc
, rtc_data
.ce_msg
.ce_msg
, tm
);
859 #ifdef CONFIG_PROC_FS
860 static int mf_cmdline_proc_show(struct seq_file
*m
, void *v
)
863 struct vsp_cmd_data vsp_cmd
;
867 /* The HV appears to return no more than 256 bytes of command line */
868 page
= kmalloc(256, GFP_KERNEL
);
872 dma_addr
= iseries_hv_map(page
, 256, DMA_FROM_DEVICE
);
873 if (dma_addr
== DMA_ERROR_CODE
) {
877 memset(page
, 0, 256);
878 memset(&vsp_cmd
, 0, sizeof(vsp_cmd
));
880 vsp_cmd
.sub_data
.kern
.token
= dma_addr
;
881 vsp_cmd
.sub_data
.kern
.address_type
= HvLpDma_AddressType_TceIndex
;
882 vsp_cmd
.sub_data
.kern
.side
= (u64
)m
->private;
883 vsp_cmd
.sub_data
.kern
.length
= 256;
885 rc
= signal_vsp_instruction(&vsp_cmd
);
886 iseries_hv_unmap(dma_addr
, 256, DMA_FROM_DEVICE
);
891 if (vsp_cmd
.result_code
!= 0) {
896 while (p
- page
< 256) {
897 if (*p
== '\0' || *p
== '\n') {
904 seq_write(m
, page
, p
- page
);
909 static int mf_cmdline_proc_open(struct inode
*inode
, struct file
*file
)
911 return single_open(file
, mf_cmdline_proc_show
, PDE(inode
)->data
);
915 static int mf_getVmlinuxChunk(char *buffer
, int *size
, int offset
, u64 side
)
917 struct vsp_cmd_data vsp_cmd
;
922 dma_addr
= iseries_hv_map(buffer
, len
, DMA_FROM_DEVICE
);
923 memset(buffer
, 0, len
);
924 memset(&vsp_cmd
, 0, sizeof(vsp_cmd
));
926 vsp_cmd
.sub_data
.kern
.token
= dma_addr
;
927 vsp_cmd
.sub_data
.kern
.address_type
= HvLpDma_AddressType_TceIndex
;
928 vsp_cmd
.sub_data
.kern
.side
= side
;
929 vsp_cmd
.sub_data
.kern
.offset
= offset
;
930 vsp_cmd
.sub_data
.kern
.length
= len
;
932 rc
= signal_vsp_instruction(&vsp_cmd
);
934 if (vsp_cmd
.result_code
== 0)
935 *size
= vsp_cmd
.sub_data
.length_out
;
940 iseries_hv_unmap(dma_addr
, len
, DMA_FROM_DEVICE
);
945 static int proc_mf_dump_vmlinux(char *page
, char **start
, off_t off
,
946 int count
, int *eof
, void *data
)
948 int sizeToGet
= count
;
950 if (!capable(CAP_SYS_ADMIN
))
953 if (mf_getVmlinuxChunk(page
, &sizeToGet
, off
, (u64
)data
) == 0) {
954 if (sizeToGet
!= 0) {
966 static int mf_side_proc_show(struct seq_file
*m
, void *v
)
968 char mf_current_side
= ' ';
969 struct vsp_cmd_data vsp_cmd
;
971 memset(&vsp_cmd
, 0, sizeof(vsp_cmd
));
973 vsp_cmd
.sub_data
.ipl_type
= 0;
976 if (signal_vsp_instruction(&vsp_cmd
) == 0) {
977 if (vsp_cmd
.result_code
== 0) {
978 switch (vsp_cmd
.sub_data
.ipl_type
) {
979 case 0: mf_current_side
= 'A';
981 case 1: mf_current_side
= 'B';
983 case 2: mf_current_side
= 'C';
985 default: mf_current_side
= 'D';
991 seq_printf(m
, "%c\n", mf_current_side
);
995 static int mf_side_proc_open(struct inode
*inode
, struct file
*file
)
997 return single_open(file
, mf_side_proc_show
, NULL
);
1000 static ssize_t
mf_side_proc_write(struct file
*file
, const char __user
*buffer
,
1001 size_t count
, loff_t
*pos
)
1005 struct vsp_cmd_data vsp_cmd
;
1007 if (!capable(CAP_SYS_ADMIN
))
1013 if (get_user(side
, buffer
))
1017 case 'A': newSide
= 0;
1019 case 'B': newSide
= 1;
1021 case 'C': newSide
= 2;
1023 case 'D': newSide
= 3;
1026 printk(KERN_ERR
"mf_proc.c: proc_mf_change_side: invalid side\n");
1030 memset(&vsp_cmd
, 0, sizeof(vsp_cmd
));
1031 vsp_cmd
.sub_data
.ipl_type
= newSide
;
1034 (void)signal_vsp_instruction(&vsp_cmd
);
1039 static const struct file_operations mf_side_proc_fops
= {
1040 .owner
= THIS_MODULE
,
1041 .open
= mf_side_proc_open
,
1043 .llseek
= seq_lseek
,
1044 .release
= single_release
,
1045 .write
= mf_side_proc_write
,
1049 static void mf_getSrcHistory(char *buffer
, int size
)
1051 struct IplTypeReturnStuff return_stuff
;
1052 struct pending_event
*ev
= new_pending_event();
1056 pages
[0] = kmalloc(4096, GFP_ATOMIC
);
1057 pages
[1] = kmalloc(4096, GFP_ATOMIC
);
1058 pages
[2] = kmalloc(4096, GFP_ATOMIC
);
1059 pages
[3] = kmalloc(4096, GFP_ATOMIC
);
1060 if ((ev
== NULL
) || (pages
[0] == NULL
) || (pages
[1] == NULL
)
1061 || (pages
[2] == NULL
) || (pages
[3] == NULL
))
1064 return_stuff
.xType
= 0;
1065 return_stuff
.xRc
= 0;
1066 return_stuff
.xDone
= 0;
1067 ev
->event
.hp_lp_event
.xSubtype
= 6;
1068 ev
->event
.hp_lp_event
.x
.xSubtypeData
=
1069 subtype_data('M', 'F', 'V', 'I');
1070 ev
->event
.data
.vsp_cmd
.xEvent
= &return_stuff
;
1071 ev
->event
.data
.vsp_cmd
.cmd
= 4;
1072 ev
->event
.data
.vsp_cmd
.lp_index
= HvLpConfig_getLpIndex();
1073 ev
->event
.data
.vsp_cmd
.result_code
= 0xFF;
1074 ev
->event
.data
.vsp_cmd
.reserved
= 0;
1075 ev
->event
.data
.vsp_cmd
.sub_data
.page
[0] = iseries_hv_addr(pages
[0]);
1076 ev
->event
.data
.vsp_cmd
.sub_data
.page
[1] = iseries_hv_addr(pages
[1]);
1077 ev
->event
.data
.vsp_cmd
.sub_data
.page
[2] = iseries_hv_addr(pages
[2]);
1078 ev
->event
.data
.vsp_cmd
.sub_data
.page
[3] = iseries_hv_addr(pages
[3]);
1080 if (signal_event(ev
) != 0)
1083 while (return_stuff
.xDone
!= 1)
1085 if (return_stuff
.xRc
== 0)
1086 memcpy(buffer
, pages
[0], size
);
1094 static int mf_src_proc_show(struct seq_file
*m
, void *v
)
1099 mf_getSrcHistory(page
, count
);
1108 *start
= page
+ off
;
1115 static int mf_src_proc_open(struct inode
*inode
, struct file
*file
)
1117 return single_open(file
, mf_src_proc_show
, NULL
);
1120 static ssize_t
mf_src_proc_write(struct file
*file
, const char __user
*buffer
,
1121 size_t count
, loff_t
*pos
)
1125 if (!capable(CAP_SYS_ADMIN
))
1128 if ((count
< 4) && (count
!= 1)) {
1129 printk(KERN_ERR
"mf_proc: invalid src\n");
1133 if (count
> (sizeof(stkbuf
) - 1))
1134 count
= sizeof(stkbuf
) - 1;
1135 if (copy_from_user(stkbuf
, buffer
, count
))
1138 if ((count
== 1) && (*stkbuf
== '\0'))
1141 mf_display_src(*(u32
*)stkbuf
);
1146 static const struct file_operations mf_src_proc_fops
= {
1147 .owner
= THIS_MODULE
,
1148 .open
= mf_src_proc_open
,
1150 .llseek
= seq_lseek
,
1151 .release
= single_release
,
1152 .write
= mf_src_proc_write
,
1155 static ssize_t
mf_cmdline_proc_write(struct file
*file
, const char __user
*buffer
,
1156 size_t count
, loff_t
*pos
)
1158 void *data
= PDE(file
->f_path
.dentry
->d_inode
)->data
;
1159 struct vsp_cmd_data vsp_cmd
;
1160 dma_addr_t dma_addr
;
1164 if (!capable(CAP_SYS_ADMIN
))
1168 page
= iseries_hv_alloc(count
, &dma_addr
, GFP_ATOMIC
);
1174 if (copy_from_user(page
, buffer
, count
))
1177 memset(&vsp_cmd
, 0, sizeof(vsp_cmd
));
1179 vsp_cmd
.sub_data
.kern
.token
= dma_addr
;
1180 vsp_cmd
.sub_data
.kern
.address_type
= HvLpDma_AddressType_TceIndex
;
1181 vsp_cmd
.sub_data
.kern
.side
= (u64
)data
;
1182 vsp_cmd
.sub_data
.kern
.length
= count
;
1184 (void)signal_vsp_instruction(&vsp_cmd
);
1188 iseries_hv_free(count
, page
, dma_addr
);
1193 static const struct file_operations mf_cmdline_proc_fops
= {
1194 .owner
= THIS_MODULE
,
1195 .open
= mf_cmdline_proc_open
,
1197 .llseek
= seq_lseek
,
1198 .release
= single_release
,
1199 .write
= mf_cmdline_proc_write
,
1202 static ssize_t
proc_mf_change_vmlinux(struct file
*file
,
1203 const char __user
*buf
,
1204 size_t count
, loff_t
*ppos
)
1206 struct proc_dir_entry
*dp
= PDE(file
->f_path
.dentry
->d_inode
);
1208 dma_addr_t dma_addr
;
1210 struct vsp_cmd_data vsp_cmd
;
1213 if (!capable(CAP_SYS_ADMIN
))
1217 page
= iseries_hv_alloc(count
, &dma_addr
, GFP_ATOMIC
);
1220 printk(KERN_ERR
"mf.c: couldn't allocate memory to set vmlinux chunk\n");
1224 if (copy_from_user(page
, buf
, count
))
1227 memset(&vsp_cmd
, 0, sizeof(vsp_cmd
));
1229 vsp_cmd
.sub_data
.kern
.token
= dma_addr
;
1230 vsp_cmd
.sub_data
.kern
.address_type
= HvLpDma_AddressType_TceIndex
;
1231 vsp_cmd
.sub_data
.kern
.side
= (u64
)dp
->data
;
1232 vsp_cmd
.sub_data
.kern
.offset
= *ppos
;
1233 vsp_cmd
.sub_data
.kern
.length
= count
;
1235 rc
= signal_vsp_instruction(&vsp_cmd
);
1239 if (vsp_cmd
.result_code
!= 0)
1245 iseries_hv_free(count
, page
, dma_addr
);
1250 static const struct file_operations proc_vmlinux_operations
= {
1251 .write
= proc_mf_change_vmlinux
,
1254 static int __init
mf_proc_init(void)
1256 struct proc_dir_entry
*mf_proc_root
;
1257 struct proc_dir_entry
*ent
;
1258 struct proc_dir_entry
*mf
;
1262 if (!firmware_has_feature(FW_FEATURE_ISERIES
))
1265 mf_proc_root
= proc_mkdir("iSeries/mf", NULL
);
1270 for (i
= 0; i
< 4; i
++) {
1272 mf
= proc_mkdir(name
, mf_proc_root
);
1276 ent
= proc_create_data("cmdline", S_IRUSR
|S_IWUSR
, mf
,
1277 &mf_cmdline_proc_fops
, (void *)(long)i
);
1281 if (i
== 3) /* no vmlinux entry for 'D' */
1284 ent
= proc_create_data("vmlinux", S_IFREG
|S_IWUSR
, mf
,
1285 &proc_vmlinux_operations
,
1291 ent
= proc_create("side", S_IFREG
|S_IRUSR
|S_IWUSR
, mf_proc_root
,
1292 &mf_side_proc_fops
);
1296 ent
= proc_create("src", S_IFREG
|S_IRUSR
|S_IWUSR
, mf_proc_root
,
1304 __initcall(mf_proc_init
);
1306 #endif /* CONFIG_PROC_FS */
1309 * Get the RTC from the virtual service processor
1310 * This requires flowing LpEvents to the primary partition
1312 void iSeries_get_rtc_time(struct rtc_time
*rtc_tm
)
1319 * Set the RTC in the virtual service processor
1320 * This requires flowing LpEvents to the primary partition
1322 int iSeries_set_rtc_time(struct rtc_time
*tm
)
1328 unsigned long iSeries_get_boot_time(void)
1332 mf_get_boot_rtc(&tm
);
1333 return mktime(tm
.tm_year
+ 1900, tm
.tm_mon
, tm
.tm_mday
,
1334 tm
.tm_hour
, tm
.tm_min
, tm
.tm_sec
);