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>
38 #include <asm/uaccess.h>
40 #include <asm/abs_addr.h>
41 #include <asm/firmware.h>
42 #include <asm/iseries/mf.h>
43 #include <asm/iseries/hv_lp_config.h>
44 #include <asm/iseries/hv_lp_event.h>
45 #include <asm/iseries/it_lp_queue.h>
49 static int mf_initialized
;
52 * This is the structure layout for the Machine Facilites LPAR event
62 u64 state
; /* GetStateOut */
63 u64 ipl_type
; /* GetIplTypeOut, Function02SelectIplTypeIn */
64 u64 ipl_mode
; /* GetIplModeOut, Function02SelectIplModeIn */
65 u64 page
[4]; /* GetSrcHistoryIn */
66 u64 flag
; /* GetAutoIplWhenPrimaryIplsOut,
67 SetAutoIplWhenPrimaryIplsIn,
68 WhiteButtonPowerOffIn,
69 Function08FastPowerOffIn,
70 IsSpcnRackPowerIncompleteOut */
77 } kern
; /* SetKernelImageIn, GetKernelImageIn,
78 SetKernelCmdLineIn, GetKernelCmdLineIn */
79 u32 length_out
; /* GetKernelImageOut, GetKernelCmdLineOut */
85 struct completion com
;
86 struct vsp_cmd_data
*response
;
100 typedef void (*ce_msg_comp_hdlr
)(void *token
, struct ce_msg_data
*vsp_cmd_rsp
);
102 struct ce_msg_comp_data
{
103 ce_msg_comp_hdlr handler
;
110 struct ce_msg_comp_data
*completion
;
113 struct io_mf_lp_event
{
114 struct HvLpEvent hp_lp_event
;
115 u16 subtype_result_code
;
119 struct alloc_data alloc
;
120 struct ce_msg_data ce_msg
;
121 struct vsp_cmd_data vsp_cmd
;
125 #define subtype_data(a, b, c, d) \
126 (((a) << 24) + ((b) << 16) + ((c) << 8) + (d))
129 * All outgoing event traffic is kept on a FIFO queue. The first
130 * pointer points to the one that is outstanding, and all new
131 * requests get stuck on the end. Also, we keep a certain number of
132 * preallocated pending events so that we can operate very early in
133 * the boot up sequence (before kmalloc is ready).
135 struct pending_event
{
136 struct pending_event
*next
;
137 struct io_mf_lp_event event
;
138 MFCompleteHandler hdlr
;
140 unsigned dma_data_length
;
141 unsigned remote_address
;
143 static spinlock_t pending_event_spinlock
;
144 static struct pending_event
*pending_event_head
;
145 static struct pending_event
*pending_event_tail
;
146 static struct pending_event
*pending_event_avail
;
147 #define PENDING_EVENT_PREALLOC_LEN 16
148 static struct pending_event pending_event_prealloc
[PENDING_EVENT_PREALLOC_LEN
];
151 * Put a pending event onto the available queue, so it can get reused.
152 * Attention! You must have the pending_event_spinlock before calling!
154 static void free_pending_event(struct pending_event
*ev
)
157 ev
->next
= pending_event_avail
;
158 pending_event_avail
= ev
;
163 * Enqueue the outbound event onto the stack. If the queue was
164 * empty to begin with, we must also issue it via the Hypervisor
165 * interface. There is a section of code below that will touch
166 * the first stack pointer without the protection of the pending_event_spinlock.
167 * This is OK, because we know that nobody else will be modifying
168 * the first pointer when we do this.
170 static int signal_event(struct pending_event
*ev
)
175 struct pending_event
*ev1
;
178 /* enqueue the event */
181 spin_lock_irqsave(&pending_event_spinlock
, flags
);
182 if (pending_event_head
== NULL
)
183 pending_event_head
= ev
;
186 pending_event_tail
->next
= ev
;
188 pending_event_tail
= ev
;
189 spin_unlock_irqrestore(&pending_event_spinlock
, flags
);
196 /* any DMA data to send beforehand? */
197 if (pending_event_head
->dma_data_length
> 0)
198 HvCallEvent_dmaToSp(pending_event_head
->dma_data
,
199 pending_event_head
->remote_address
,
200 pending_event_head
->dma_data_length
,
201 HvLpDma_Direction_LocalToRemote
);
203 hv_rc
= HvCallEvent_signalLpEvent(
204 &pending_event_head
->event
.hp_lp_event
);
205 if (hv_rc
!= HvLpEvent_Rc_Good
) {
206 printk(KERN_ERR
"mf.c: HvCallEvent_signalLpEvent() "
207 "failed with %d\n", (int)hv_rc
);
209 spin_lock_irqsave(&pending_event_spinlock
, flags
);
210 ev1
= pending_event_head
;
211 pending_event_head
= pending_event_head
->next
;
212 if (pending_event_head
!= NULL
)
214 spin_unlock_irqrestore(&pending_event_spinlock
, flags
);
218 else if (ev1
->hdlr
!= NULL
)
219 (*ev1
->hdlr
)((void *)ev1
->event
.hp_lp_event
.xCorrelationToken
, -EIO
);
221 spin_lock_irqsave(&pending_event_spinlock
, flags
);
222 free_pending_event(ev1
);
223 spin_unlock_irqrestore(&pending_event_spinlock
, flags
);
231 * Allocate a new pending_event structure, and initialize it.
233 static struct pending_event
*new_pending_event(void)
235 struct pending_event
*ev
= NULL
;
236 HvLpIndex primary_lp
= HvLpConfig_getPrimaryLpIndex();
238 struct HvLpEvent
*hev
;
240 spin_lock_irqsave(&pending_event_spinlock
, flags
);
241 if (pending_event_avail
!= NULL
) {
242 ev
= pending_event_avail
;
243 pending_event_avail
= pending_event_avail
->next
;
245 spin_unlock_irqrestore(&pending_event_spinlock
, flags
);
247 ev
= kmalloc(sizeof(struct pending_event
), GFP_ATOMIC
);
249 printk(KERN_ERR
"mf.c: unable to kmalloc %ld bytes\n",
250 sizeof(struct pending_event
));
254 memset(ev
, 0, sizeof(struct pending_event
));
255 hev
= &ev
->event
.hp_lp_event
;
256 hev
->flags
= HV_LP_EVENT_VALID
| HV_LP_EVENT_DO_ACK
| HV_LP_EVENT_INT
;
257 hev
->xType
= HvLpEvent_Type_MachineFac
;
258 hev
->xSourceLp
= HvLpConfig_getLpIndex();
259 hev
->xTargetLp
= primary_lp
;
260 hev
->xSizeMinus1
= sizeof(ev
->event
) - 1;
261 hev
->xRc
= HvLpEvent_Rc_Good
;
262 hev
->xSourceInstanceId
= HvCallEvent_getSourceLpInstanceId(primary_lp
,
263 HvLpEvent_Type_MachineFac
);
264 hev
->xTargetInstanceId
= HvCallEvent_getTargetLpInstanceId(primary_lp
,
265 HvLpEvent_Type_MachineFac
);
270 static int signal_vsp_instruction(struct vsp_cmd_data
*vsp_cmd
)
272 struct pending_event
*ev
= new_pending_event();
274 struct vsp_rsp_data response
;
279 init_completion(&response
.com
);
280 response
.response
= vsp_cmd
;
281 ev
->event
.hp_lp_event
.xSubtype
= 6;
282 ev
->event
.hp_lp_event
.x
.xSubtypeData
=
283 subtype_data('M', 'F', 'V', 'I');
284 ev
->event
.data
.vsp_cmd
.token
= (u64
)&response
;
285 ev
->event
.data
.vsp_cmd
.cmd
= vsp_cmd
->cmd
;
286 ev
->event
.data
.vsp_cmd
.lp_index
= HvLpConfig_getLpIndex();
287 ev
->event
.data
.vsp_cmd
.result_code
= 0xFF;
288 ev
->event
.data
.vsp_cmd
.reserved
= 0;
289 memcpy(&(ev
->event
.data
.vsp_cmd
.sub_data
),
290 &(vsp_cmd
->sub_data
), sizeof(vsp_cmd
->sub_data
));
293 rc
= signal_event(ev
);
295 wait_for_completion(&response
.com
);
301 * Send a 12-byte CE message to the primary partition VSP object
303 static int signal_ce_msg(char *ce_msg
, struct ce_msg_comp_data
*completion
)
305 struct pending_event
*ev
= new_pending_event();
310 ev
->event
.hp_lp_event
.xSubtype
= 0;
311 ev
->event
.hp_lp_event
.x
.xSubtypeData
=
312 subtype_data('M', 'F', 'C', 'E');
313 memcpy(ev
->event
.data
.ce_msg
.ce_msg
, ce_msg
, 12);
314 ev
->event
.data
.ce_msg
.completion
= completion
;
315 return signal_event(ev
);
319 * Send a 12-byte CE message (with no data) to the primary partition VSP object
321 static int signal_ce_msg_simple(u8 ce_op
, struct ce_msg_comp_data
*completion
)
325 memset(ce_msg
, 0, sizeof(ce_msg
));
327 return signal_ce_msg(ce_msg
, completion
);
331 * Send a 12-byte CE message and DMA data to the primary partition VSP object
333 static int dma_and_signal_ce_msg(char *ce_msg
,
334 struct ce_msg_comp_data
*completion
, void *dma_data
,
335 unsigned dma_data_length
, unsigned remote_address
)
337 struct pending_event
*ev
= new_pending_event();
342 ev
->event
.hp_lp_event
.xSubtype
= 0;
343 ev
->event
.hp_lp_event
.x
.xSubtypeData
=
344 subtype_data('M', 'F', 'C', 'E');
345 memcpy(ev
->event
.data
.ce_msg
.ce_msg
, ce_msg
, 12);
346 ev
->event
.data
.ce_msg
.completion
= completion
;
347 memcpy(ev
->dma_data
, dma_data
, dma_data_length
);
348 ev
->dma_data_length
= dma_data_length
;
349 ev
->remote_address
= remote_address
;
350 return signal_event(ev
);
354 * Initiate a nice (hopefully) shutdown of Linux. We simply are
355 * going to try and send the init process a SIGINT signal. If
356 * this fails (why?), we'll simply force it off in a not-so-nice
359 static int shutdown(void)
361 int rc
= kill_cad_pid(SIGINT
, 1);
364 printk(KERN_ALERT
"mf.c: SIGINT to init failed (%d), "
365 "hard shutdown commencing\n", rc
);
368 printk(KERN_INFO
"mf.c: init has been successfully notified "
369 "to proceed with shutdown\n");
374 * The primary partition VSP object is sending us a new
375 * event flow. Handle it...
377 static void handle_int(struct io_mf_lp_event
*event
)
379 struct ce_msg_data
*ce_msg_data
;
380 struct ce_msg_data
*pce_msg_data
;
382 struct pending_event
*pev
;
384 /* ack the interrupt */
385 event
->hp_lp_event
.xRc
= HvLpEvent_Rc_Good
;
386 HvCallEvent_ackLpEvent(&event
->hp_lp_event
);
388 /* process interrupt */
389 switch (event
->hp_lp_event
.xSubtype
) {
390 case 0: /* CE message */
391 ce_msg_data
= &event
->data
.ce_msg
;
392 switch (ce_msg_data
->ce_msg
[3]) {
393 case 0x5B: /* power control notification */
394 if ((ce_msg_data
->ce_msg
[5] & 0x20) != 0) {
395 printk(KERN_INFO
"mf.c: Commencing partition shutdown\n");
397 signal_ce_msg_simple(0xDB, NULL
);
400 case 0xC0: /* get time */
401 spin_lock_irqsave(&pending_event_spinlock
, flags
);
402 pev
= pending_event_head
;
404 pending_event_head
= pending_event_head
->next
;
405 spin_unlock_irqrestore(&pending_event_spinlock
, flags
);
408 pce_msg_data
= &pev
->event
.data
.ce_msg
;
409 if (pce_msg_data
->ce_msg
[3] != 0x40)
411 if (pce_msg_data
->completion
!= NULL
) {
412 ce_msg_comp_hdlr handler
=
413 pce_msg_data
->completion
->handler
;
414 void *token
= pce_msg_data
->completion
->token
;
417 (*handler
)(token
, ce_msg_data
);
419 spin_lock_irqsave(&pending_event_spinlock
, flags
);
420 free_pending_event(pev
);
421 spin_unlock_irqrestore(&pending_event_spinlock
, flags
);
422 /* send next waiting event */
423 if (pending_event_head
!= NULL
)
428 case 1: /* IT sys shutdown */
429 printk(KERN_INFO
"mf.c: Commencing system shutdown\n");
436 * The primary partition VSP object is acknowledging the receipt
437 * of a flow we sent to them. If there are other flows queued
438 * up, we must send another one now...
440 static void handle_ack(struct io_mf_lp_event
*event
)
443 struct pending_event
*two
= NULL
;
444 unsigned long free_it
= 0;
445 struct ce_msg_data
*ce_msg_data
;
446 struct ce_msg_data
*pce_msg_data
;
447 struct vsp_rsp_data
*rsp
;
449 /* handle current event */
450 if (pending_event_head
== NULL
) {
451 printk(KERN_ERR
"mf.c: stack empty for receiving ack\n");
455 switch (event
->hp_lp_event
.xSubtype
) {
457 ce_msg_data
= &event
->data
.ce_msg
;
458 if (ce_msg_data
->ce_msg
[3] != 0x40) {
462 if (ce_msg_data
->ce_msg
[2] == 0)
465 pce_msg_data
= &pending_event_head
->event
.data
.ce_msg
;
466 if (pce_msg_data
->completion
!= NULL
) {
467 ce_msg_comp_hdlr handler
=
468 pce_msg_data
->completion
->handler
;
469 void *token
= pce_msg_data
->completion
->token
;
472 (*handler
)(token
, ce_msg_data
);
475 case 4: /* allocate */
476 case 5: /* deallocate */
477 if (pending_event_head
->hdlr
!= NULL
)
478 (*pending_event_head
->hdlr
)((void *)event
->hp_lp_event
.xCorrelationToken
, event
->data
.alloc
.count
);
483 rsp
= (struct vsp_rsp_data
*)event
->data
.vsp_cmd
.token
;
485 printk(KERN_ERR
"mf.c: no rsp\n");
488 if (rsp
->response
!= NULL
)
489 memcpy(rsp
->response
, &event
->data
.vsp_cmd
,
490 sizeof(event
->data
.vsp_cmd
));
495 /* remove from queue */
496 spin_lock_irqsave(&pending_event_spinlock
, flags
);
497 if ((pending_event_head
!= NULL
) && (free_it
== 1)) {
498 struct pending_event
*oldHead
= pending_event_head
;
500 pending_event_head
= pending_event_head
->next
;
501 two
= pending_event_head
;
502 free_pending_event(oldHead
);
504 spin_unlock_irqrestore(&pending_event_spinlock
, flags
);
506 /* send next waiting event */
512 * This is the generic event handler we are registering with
513 * the Hypervisor. Ensure the flows are for us, and then
514 * parse it enough to know if it is an interrupt or an
517 static void hv_handler(struct HvLpEvent
*event
)
519 if ((event
!= NULL
) && (event
->xType
== HvLpEvent_Type_MachineFac
)) {
520 if (hvlpevent_is_ack(event
))
521 handle_ack((struct io_mf_lp_event
*)event
);
523 handle_int((struct io_mf_lp_event
*)event
);
525 printk(KERN_ERR
"mf.c: alien event received\n");
529 * Global kernel interface to allocate and seed events into the
532 void mf_allocate_lp_events(HvLpIndex target_lp
, HvLpEvent_Type type
,
533 unsigned size
, unsigned count
, MFCompleteHandler hdlr
,
536 struct pending_event
*ev
= new_pending_event();
542 ev
->event
.hp_lp_event
.xSubtype
= 4;
543 ev
->event
.hp_lp_event
.xCorrelationToken
= (u64
)user_token
;
544 ev
->event
.hp_lp_event
.x
.xSubtypeData
=
545 subtype_data('M', 'F', 'M', 'A');
546 ev
->event
.data
.alloc
.target_lp
= target_lp
;
547 ev
->event
.data
.alloc
.type
= type
;
548 ev
->event
.data
.alloc
.size
= size
;
549 ev
->event
.data
.alloc
.count
= count
;
551 rc
= signal_event(ev
);
553 if ((rc
!= 0) && (hdlr
!= NULL
))
554 (*hdlr
)(user_token
, rc
);
556 EXPORT_SYMBOL(mf_allocate_lp_events
);
559 * Global kernel interface to unseed and deallocate events already in
562 void mf_deallocate_lp_events(HvLpIndex target_lp
, HvLpEvent_Type type
,
563 unsigned count
, MFCompleteHandler hdlr
, void *user_token
)
565 struct pending_event
*ev
= new_pending_event();
571 ev
->event
.hp_lp_event
.xSubtype
= 5;
572 ev
->event
.hp_lp_event
.xCorrelationToken
= (u64
)user_token
;
573 ev
->event
.hp_lp_event
.x
.xSubtypeData
=
574 subtype_data('M', 'F', 'M', 'D');
575 ev
->event
.data
.alloc
.target_lp
= target_lp
;
576 ev
->event
.data
.alloc
.type
= type
;
577 ev
->event
.data
.alloc
.count
= count
;
579 rc
= signal_event(ev
);
581 if ((rc
!= 0) && (hdlr
!= NULL
))
582 (*hdlr
)(user_token
, rc
);
584 EXPORT_SYMBOL(mf_deallocate_lp_events
);
587 * Global kernel interface to tell the VSP object in the primary
588 * partition to power this partition off.
590 void mf_power_off(void)
592 printk(KERN_INFO
"mf.c: Down it goes...\n");
593 signal_ce_msg_simple(0x4d, NULL
);
599 * Global kernel interface to tell the VSP object in the primary
600 * partition to reboot this partition.
602 void mf_reboot(char *cmd
)
604 printk(KERN_INFO
"mf.c: Preparing to bounce...\n");
605 signal_ce_msg_simple(0x4e, NULL
);
611 * Display a single word SRC onto the VSP control panel.
613 void mf_display_src(u32 word
)
617 memset(ce
, 0, sizeof(ce
));
624 signal_ce_msg(ce
, NULL
);
628 * Display a single word SRC of the form "PROGXXXX" on the VSP control panel.
630 static __init
void mf_display_progress_src(u16 value
)
635 memcpy(ce
, "\x00\x00\x04\x4A\x00\x00\x00\x48\x00\x00\x00\x00", 12);
636 memcpy(src
, "\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00"
637 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
638 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
639 "\x00\x00\x00\x00PROGxxxx ",
642 src
[7] = value
& 255;
643 src
[44] = "0123456789ABCDEF"[(value
>> 12) & 15];
644 src
[45] = "0123456789ABCDEF"[(value
>> 8) & 15];
645 src
[46] = "0123456789ABCDEF"[(value
>> 4) & 15];
646 src
[47] = "0123456789ABCDEF"[value
& 15];
647 dma_and_signal_ce_msg(ce
, NULL
, src
, sizeof(src
), 9 * 64 * 1024);
651 * Clear the VSP control panel. Used to "erase" an SRC that was
652 * previously displayed.
654 static void mf_clear_src(void)
656 signal_ce_msg_simple(0x4b, NULL
);
659 void __init
mf_display_progress(u16 value
)
667 mf_display_progress_src(value
);
671 * Initialization code here.
673 void __init
mf_init(void)
677 spin_lock_init(&pending_event_spinlock
);
679 for (i
= 0; i
< PENDING_EVENT_PREALLOC_LEN
; i
++)
680 free_pending_event(&pending_event_prealloc
[i
]);
682 HvLpEvent_registerHandler(HvLpEvent_Type_MachineFac
, &hv_handler
);
684 /* virtual continue ack */
685 signal_ce_msg_simple(0x57, NULL
);
690 printk(KERN_NOTICE
"mf.c: iSeries Linux LPAR Machine Facilities "
694 struct rtc_time_data
{
695 struct completion com
;
696 struct ce_msg_data ce_msg
;
700 static void get_rtc_time_complete(void *token
, struct ce_msg_data
*ce_msg
)
702 struct rtc_time_data
*rtc
= token
;
704 memcpy(&rtc
->ce_msg
, ce_msg
, sizeof(rtc
->ce_msg
));
709 static int mf_set_rtc(struct rtc_time
*tm
)
712 u8 day
, mon
, hour
, min
, sec
, y1
, y2
;
715 year
= 1900 + tm
->tm_year
;
723 mon
= tm
->tm_mon
+ 1;
727 hour
= bin2bcd(hour
);
733 memset(ce_time
, 0, sizeof(ce_time
));
743 return signal_ce_msg(ce_time
, NULL
);
746 static int rtc_set_tm(int rc
, u8
*ce_msg
, struct rtc_time
*tm
)
761 if ((ce_msg
[2] == 0xa9) ||
762 (ce_msg
[2] == 0xaf)) {
763 /* TOD clock is not set */
782 hour
= bcd2bin(hour
);
785 year
= bcd2bin(year
);
801 static int mf_get_rtc(struct rtc_time
*tm
)
803 struct ce_msg_comp_data ce_complete
;
804 struct rtc_time_data rtc_data
;
807 memset(&ce_complete
, 0, sizeof(ce_complete
));
808 memset(&rtc_data
, 0, sizeof(rtc_data
));
809 init_completion(&rtc_data
.com
);
810 ce_complete
.handler
= &get_rtc_time_complete
;
811 ce_complete
.token
= &rtc_data
;
812 rc
= signal_ce_msg_simple(0x40, &ce_complete
);
815 wait_for_completion(&rtc_data
.com
);
816 return rtc_set_tm(rtc_data
.rc
, rtc_data
.ce_msg
.ce_msg
, tm
);
819 struct boot_rtc_time_data
{
821 struct ce_msg_data ce_msg
;
825 static void get_boot_rtc_time_complete(void *token
, struct ce_msg_data
*ce_msg
)
827 struct boot_rtc_time_data
*rtc
= token
;
829 memcpy(&rtc
->ce_msg
, ce_msg
, sizeof(rtc
->ce_msg
));
834 static int mf_get_boot_rtc(struct rtc_time
*tm
)
836 struct ce_msg_comp_data ce_complete
;
837 struct boot_rtc_time_data rtc_data
;
840 memset(&ce_complete
, 0, sizeof(ce_complete
));
841 memset(&rtc_data
, 0, sizeof(rtc_data
));
843 ce_complete
.handler
= &get_boot_rtc_time_complete
;
844 ce_complete
.token
= &rtc_data
;
845 rc
= signal_ce_msg_simple(0x40, &ce_complete
);
848 /* We need to poll here as we are not yet taking interrupts */
849 while (rtc_data
.busy
) {
850 if (hvlpevent_is_pending())
851 process_hvlpevents();
853 return rtc_set_tm(rtc_data
.rc
, rtc_data
.ce_msg
.ce_msg
, tm
);
856 #ifdef CONFIG_PROC_FS
858 static int proc_mf_dump_cmdline(char *page
, char **start
, off_t off
,
859 int count
, int *eof
, void *data
)
863 struct vsp_cmd_data vsp_cmd
;
867 /* The HV appears to return no more than 256 bytes of command line */
870 if ((off
+ count
) > 256)
873 dma_addr
= iseries_hv_map(page
, off
+ count
, DMA_FROM_DEVICE
);
874 if (dma_mapping_error(NULL
, dma_addr
))
876 memset(page
, 0, off
+ count
);
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
)data
;
882 vsp_cmd
.sub_data
.kern
.length
= off
+ count
;
884 rc
= signal_vsp_instruction(&vsp_cmd
);
885 iseries_hv_unmap(dma_addr
, off
+ count
, DMA_FROM_DEVICE
);
888 if (vsp_cmd
.result_code
!= 0)
892 while (len
< (off
+ count
)) {
893 if ((*p
== '\0') || (*p
== '\n')) {
913 static int mf_getVmlinuxChunk(char *buffer
, int *size
, int offset
, u64 side
)
915 struct vsp_cmd_data vsp_cmd
;
920 dma_addr
= iseries_hv_map(buffer
, len
, DMA_FROM_DEVICE
);
921 memset(buffer
, 0, len
);
922 memset(&vsp_cmd
, 0, sizeof(vsp_cmd
));
924 vsp_cmd
.sub_data
.kern
.token
= dma_addr
;
925 vsp_cmd
.sub_data
.kern
.address_type
= HvLpDma_AddressType_TceIndex
;
926 vsp_cmd
.sub_data
.kern
.side
= side
;
927 vsp_cmd
.sub_data
.kern
.offset
= offset
;
928 vsp_cmd
.sub_data
.kern
.length
= len
;
930 rc
= signal_vsp_instruction(&vsp_cmd
);
932 if (vsp_cmd
.result_code
== 0)
933 *size
= vsp_cmd
.sub_data
.length_out
;
938 iseries_hv_unmap(dma_addr
, len
, DMA_FROM_DEVICE
);
943 static int proc_mf_dump_vmlinux(char *page
, char **start
, off_t off
,
944 int count
, int *eof
, void *data
)
946 int sizeToGet
= count
;
948 if (!capable(CAP_SYS_ADMIN
))
951 if (mf_getVmlinuxChunk(page
, &sizeToGet
, off
, (u64
)data
) == 0) {
952 if (sizeToGet
!= 0) {
964 static int proc_mf_dump_side(char *page
, char **start
, off_t off
,
965 int count
, int *eof
, void *data
)
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 len
= sprintf(page
, "%c\n", mf_current_side
);
993 if (len
<= (off
+ count
))
1004 static int proc_mf_change_side(struct file
*file
, const char __user
*buffer
,
1005 unsigned long count
, void *data
)
1009 struct vsp_cmd_data vsp_cmd
;
1011 if (!capable(CAP_SYS_ADMIN
))
1017 if (get_user(side
, buffer
))
1021 case 'A': newSide
= 0;
1023 case 'B': newSide
= 1;
1025 case 'C': newSide
= 2;
1027 case 'D': newSide
= 3;
1030 printk(KERN_ERR
"mf_proc.c: proc_mf_change_side: invalid side\n");
1034 memset(&vsp_cmd
, 0, sizeof(vsp_cmd
));
1035 vsp_cmd
.sub_data
.ipl_type
= newSide
;
1038 (void)signal_vsp_instruction(&vsp_cmd
);
1044 static void mf_getSrcHistory(char *buffer
, int size
)
1046 struct IplTypeReturnStuff return_stuff
;
1047 struct pending_event
*ev
= new_pending_event();
1051 pages
[0] = kmalloc(4096, GFP_ATOMIC
);
1052 pages
[1] = kmalloc(4096, GFP_ATOMIC
);
1053 pages
[2] = kmalloc(4096, GFP_ATOMIC
);
1054 pages
[3] = kmalloc(4096, GFP_ATOMIC
);
1055 if ((ev
== NULL
) || (pages
[0] == NULL
) || (pages
[1] == NULL
)
1056 || (pages
[2] == NULL
) || (pages
[3] == NULL
))
1059 return_stuff
.xType
= 0;
1060 return_stuff
.xRc
= 0;
1061 return_stuff
.xDone
= 0;
1062 ev
->event
.hp_lp_event
.xSubtype
= 6;
1063 ev
->event
.hp_lp_event
.x
.xSubtypeData
=
1064 subtype_data('M', 'F', 'V', 'I');
1065 ev
->event
.data
.vsp_cmd
.xEvent
= &return_stuff
;
1066 ev
->event
.data
.vsp_cmd
.cmd
= 4;
1067 ev
->event
.data
.vsp_cmd
.lp_index
= HvLpConfig_getLpIndex();
1068 ev
->event
.data
.vsp_cmd
.result_code
= 0xFF;
1069 ev
->event
.data
.vsp_cmd
.reserved
= 0;
1070 ev
->event
.data
.vsp_cmd
.sub_data
.page
[0] = iseries_hv_addr(pages
[0]);
1071 ev
->event
.data
.vsp_cmd
.sub_data
.page
[1] = iseries_hv_addr(pages
[1]);
1072 ev
->event
.data
.vsp_cmd
.sub_data
.page
[2] = iseries_hv_addr(pages
[2]);
1073 ev
->event
.data
.vsp_cmd
.sub_data
.page
[3] = iseries_hv_addr(pages
[3]);
1075 if (signal_event(ev
) != 0)
1078 while (return_stuff
.xDone
!= 1)
1080 if (return_stuff
.xRc
== 0)
1081 memcpy(buffer
, pages
[0], size
);
1089 static int proc_mf_dump_src(char *page
, char **start
, off_t off
,
1090 int count
, int *eof
, void *data
)
1095 mf_getSrcHistory(page
, count
);
1104 *start
= page
+ off
;
1111 static int proc_mf_change_src(struct file
*file
, const char __user
*buffer
,
1112 unsigned long count
, void *data
)
1116 if (!capable(CAP_SYS_ADMIN
))
1119 if ((count
< 4) && (count
!= 1)) {
1120 printk(KERN_ERR
"mf_proc: invalid src\n");
1124 if (count
> (sizeof(stkbuf
) - 1))
1125 count
= sizeof(stkbuf
) - 1;
1126 if (copy_from_user(stkbuf
, buffer
, count
))
1129 if ((count
== 1) && (*stkbuf
== '\0'))
1132 mf_display_src(*(u32
*)stkbuf
);
1137 static int proc_mf_change_cmdline(struct file
*file
, const char __user
*buffer
,
1138 unsigned long count
, void *data
)
1140 struct vsp_cmd_data vsp_cmd
;
1141 dma_addr_t dma_addr
;
1145 if (!capable(CAP_SYS_ADMIN
))
1149 page
= iseries_hv_alloc(count
, &dma_addr
, GFP_ATOMIC
);
1155 if (copy_from_user(page
, buffer
, count
))
1158 memset(&vsp_cmd
, 0, sizeof(vsp_cmd
));
1160 vsp_cmd
.sub_data
.kern
.token
= dma_addr
;
1161 vsp_cmd
.sub_data
.kern
.address_type
= HvLpDma_AddressType_TceIndex
;
1162 vsp_cmd
.sub_data
.kern
.side
= (u64
)data
;
1163 vsp_cmd
.sub_data
.kern
.length
= count
;
1165 (void)signal_vsp_instruction(&vsp_cmd
);
1169 iseries_hv_free(count
, page
, dma_addr
);
1174 static ssize_t
proc_mf_change_vmlinux(struct file
*file
,
1175 const char __user
*buf
,
1176 size_t count
, loff_t
*ppos
)
1178 struct proc_dir_entry
*dp
= PDE(file
->f_path
.dentry
->d_inode
);
1180 dma_addr_t dma_addr
;
1182 struct vsp_cmd_data vsp_cmd
;
1185 if (!capable(CAP_SYS_ADMIN
))
1189 page
= iseries_hv_alloc(count
, &dma_addr
, GFP_ATOMIC
);
1192 printk(KERN_ERR
"mf.c: couldn't allocate memory to set vmlinux chunk\n");
1196 if (copy_from_user(page
, buf
, count
))
1199 memset(&vsp_cmd
, 0, sizeof(vsp_cmd
));
1201 vsp_cmd
.sub_data
.kern
.token
= dma_addr
;
1202 vsp_cmd
.sub_data
.kern
.address_type
= HvLpDma_AddressType_TceIndex
;
1203 vsp_cmd
.sub_data
.kern
.side
= (u64
)dp
->data
;
1204 vsp_cmd
.sub_data
.kern
.offset
= *ppos
;
1205 vsp_cmd
.sub_data
.kern
.length
= count
;
1207 rc
= signal_vsp_instruction(&vsp_cmd
);
1211 if (vsp_cmd
.result_code
!= 0)
1217 iseries_hv_free(count
, page
, dma_addr
);
1222 static const struct file_operations proc_vmlinux_operations
= {
1223 .write
= proc_mf_change_vmlinux
,
1226 static int __init
mf_proc_init(void)
1228 struct proc_dir_entry
*mf_proc_root
;
1229 struct proc_dir_entry
*ent
;
1230 struct proc_dir_entry
*mf
;
1234 if (!firmware_has_feature(FW_FEATURE_ISERIES
))
1237 mf_proc_root
= proc_mkdir("iSeries/mf", NULL
);
1242 for (i
= 0; i
< 4; i
++) {
1244 mf
= proc_mkdir(name
, mf_proc_root
);
1248 ent
= create_proc_entry("cmdline", S_IFREG
|S_IRUSR
|S_IWUSR
, mf
);
1251 ent
->data
= (void *)(long)i
;
1252 ent
->read_proc
= proc_mf_dump_cmdline
;
1253 ent
->write_proc
= proc_mf_change_cmdline
;
1255 if (i
== 3) /* no vmlinux entry for 'D' */
1258 ent
= proc_create_data("vmlinux", S_IFREG
|S_IWUSR
, mf
,
1259 &proc_vmlinux_operations
,
1265 ent
= create_proc_entry("side", S_IFREG
|S_IRUSR
|S_IWUSR
, mf_proc_root
);
1268 ent
->data
= (void *)0;
1269 ent
->read_proc
= proc_mf_dump_side
;
1270 ent
->write_proc
= proc_mf_change_side
;
1272 ent
= create_proc_entry("src", S_IFREG
|S_IRUSR
|S_IWUSR
, mf_proc_root
);
1275 ent
->data
= (void *)0;
1276 ent
->read_proc
= proc_mf_dump_src
;
1277 ent
->write_proc
= proc_mf_change_src
;
1282 __initcall(mf_proc_init
);
1284 #endif /* CONFIG_PROC_FS */
1287 * Get the RTC from the virtual service processor
1288 * This requires flowing LpEvents to the primary partition
1290 void iSeries_get_rtc_time(struct rtc_time
*rtc_tm
)
1297 * Set the RTC in the virtual service processor
1298 * This requires flowing LpEvents to the primary partition
1300 int iSeries_set_rtc_time(struct rtc_time
*tm
)
1306 unsigned long iSeries_get_boot_time(void)
1310 mf_get_boot_rtc(&tm
);
1311 return mktime(tm
.tm_year
+ 1900, tm
.tm_mon
, tm
.tm_mday
,
1312 tm
.tm_hour
, tm
.tm_min
, tm
.tm_sec
);