3 * Copyright (C) 2001 Troy D. Armstrong 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 <asm/iSeries/mf.h>
28 #include <linux/types.h>
29 #include <linux/errno.h>
30 #include <linux/kernel.h>
31 #include <linux/init.h>
33 #include <linux/module.h>
34 #include <linux/completion.h>
35 #include <asm/iSeries/HvLpConfig.h>
36 #include <linux/slab.h>
37 #include <linux/delay.h>
38 #include <asm/nvram.h>
40 #include <asm/iSeries/ItSpCommArea.h>
41 #include <asm/uaccess.h>
42 #include <linux/dma-mapping.h>
43 #include <linux/bcd.h>
44 #include <asm/iSeries/vio.h>
47 * This is the structure layout for the Machine Facilites LPAR event
56 union safe_cast token;
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 VspCmdData *response;
100 typedef void (*CeMsgCompleteHandler)(void *token, struct CeMsgData *vspCmdRsp);
102 struct CeMsgCompleteData {
103 CeMsgCompleteHandler handler;
110 struct CeMsgCompleteData *completion;
114 struct HvLpEvent hp_lp_event;
115 u16 subtype_result_code;
119 struct AllocData alloc;
120 struct CeMsgData ce_msg;
121 struct VspCmdData 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 IoMFLpEvent 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 static struct pending_event pending_event_prealloc[16];
150 * Put a pending event onto the available queue, so it can get reused.
151 * Attention! You must have the pending_event_spinlock before calling!
153 static void free_pending_event(struct pending_event *ev)
156 ev->next = pending_event_avail;
157 pending_event_avail = ev;
162 * Enqueue the outbound event onto the stack. If the queue was
163 * empty to begin with, we must also issue it via the Hypervisor
164 * interface. There is a section of code below that will touch
165 * the first stack pointer without the protection of the pending_event_spinlock.
166 * This is OK, because we know that nobody else will be modifying
167 * the first pointer when we do this.
169 static int signal_event(struct pending_event *ev)
174 struct pending_event *ev1;
177 /* enqueue the event */
180 spin_lock_irqsave(&pending_event_spinlock, flags);
181 if (pending_event_head == NULL)
182 pending_event_head = ev;
185 pending_event_tail->next = ev;
187 pending_event_tail = ev;
188 spin_unlock_irqrestore(&pending_event_spinlock, flags);
195 /* any DMA data to send beforehand? */
196 if (pending_event_head->dma_data_length > 0)
197 HvCallEvent_dmaToSp(pending_event_head->dma_data,
198 pending_event_head->remote_address,
199 pending_event_head->dma_data_length,
200 HvLpDma_Direction_LocalToRemote);
202 hvRc = HvCallEvent_signalLpEvent(
203 &pending_event_head->event.hp_lp_event);
204 if (hvRc != HvLpEvent_Rc_Good) {
205 printk(KERN_ERR "mf.c: HvCallEvent_signalLpEvent() failed with %d\n",
208 spin_lock_irqsave(&pending_event_spinlock, flags);
209 ev1 = pending_event_head;
210 pending_event_head = pending_event_head->next;
211 if (pending_event_head != NULL)
213 spin_unlock_irqrestore(&pending_event_spinlock, flags);
217 else if (ev1->hdlr != NULL) {
218 union safe_cast mySafeCast;
220 mySafeCast.ptr_as_u64 = ev1->event.hp_lp_event.xCorrelationToken;
221 (*ev1->hdlr)(mySafeCast.ptr, -EIO);
224 spin_lock_irqsave(&pending_event_spinlock, flags);
225 free_pending_event(ev1);
226 spin_unlock_irqrestore(&pending_event_spinlock, flags);
234 * Allocate a new pending_event structure, and initialize it.
236 static struct pending_event *new_pending_event(void)
238 struct pending_event *ev = NULL;
239 HvLpIndex primaryLp = HvLpConfig_getPrimaryLpIndex();
241 struct HvLpEvent *hev;
243 spin_lock_irqsave(&pending_event_spinlock, flags);
244 if (pending_event_avail != NULL) {
245 ev = pending_event_avail;
246 pending_event_avail = pending_event_avail->next;
248 spin_unlock_irqrestore(&pending_event_spinlock, flags);
250 ev = kmalloc(sizeof(struct pending_event),GFP_ATOMIC);
252 printk(KERN_ERR "mf.c: unable to kmalloc %ld bytes\n",
253 sizeof(struct pending_event));
256 memset(ev, 0, sizeof(struct pending_event));
257 hev = &ev->event.hp_lp_event;
258 hev->xFlags.xValid = 1;
259 hev->xFlags.xAckType = HvLpEvent_AckType_ImmediateAck;
260 hev->xFlags.xAckInd = HvLpEvent_AckInd_DoAck;
261 hev->xFlags.xFunction = HvLpEvent_Function_Int;
262 hev->xType = HvLpEvent_Type_MachineFac;
263 hev->xSourceLp = HvLpConfig_getLpIndex();
264 hev->xTargetLp = primaryLp;
265 hev->xSizeMinus1 = sizeof(ev->event)-1;
266 hev->xRc = HvLpEvent_Rc_Good;
267 hev->xSourceInstanceId = HvCallEvent_getSourceLpInstanceId(primaryLp,
268 HvLpEvent_Type_MachineFac);
269 hev->xTargetInstanceId = HvCallEvent_getTargetLpInstanceId(primaryLp,
270 HvLpEvent_Type_MachineFac);
275 static int signal_vsp_instruction(struct VspCmdData *vspCmd)
277 struct pending_event *ev = new_pending_event();
279 struct VspRspData response;
284 init_completion(&response.com);
285 response.response = vspCmd;
286 ev->event.hp_lp_event.xSubtype = 6;
287 ev->event.hp_lp_event.x.xSubtypeData =
288 subtype_data('M', 'F', 'V', 'I');
289 ev->event.data.vsp_cmd.token.ptr = &response;
290 ev->event.data.vsp_cmd.cmd = vspCmd->cmd;
291 ev->event.data.vsp_cmd.lp_index = HvLpConfig_getLpIndex();
292 ev->event.data.vsp_cmd.result_code = 0xFF;
293 ev->event.data.vsp_cmd.reserved = 0;
294 memcpy(&(ev->event.data.vsp_cmd.sub_data),
295 &(vspCmd->sub_data), sizeof(vspCmd->sub_data));
298 rc = signal_event(ev);
300 wait_for_completion(&response.com);
306 * Send a 12-byte CE message to the primary partition VSP object
308 static int signal_ce_msg(char *ce_msg, struct CeMsgCompleteData *completion)
310 struct pending_event *ev = new_pending_event();
315 ev->event.hp_lp_event.xSubtype = 0;
316 ev->event.hp_lp_event.x.xSubtypeData =
317 subtype_data('M', 'F', 'C', 'E');
318 memcpy(ev->event.data.ce_msg.ce_msg, ce_msg, 12);
319 ev->event.data.ce_msg.completion = completion;
320 return signal_event(ev);
324 * Send a 12-byte CE message and DMA data to the primary partition VSP object
326 static int dma_and_signal_ce_msg(char *ce_msg,
327 struct CeMsgCompleteData *completion, void *dma_data,
328 unsigned dma_data_length, unsigned remote_address)
330 struct pending_event *ev = new_pending_event();
335 ev->event.hp_lp_event.xSubtype = 0;
336 ev->event.hp_lp_event.x.xSubtypeData =
337 subtype_data('M', 'F', 'C', 'E');
338 memcpy(ev->event.data.ce_msg.ce_msg, ce_msg, 12);
339 ev->event.data.ce_msg.completion = completion;
340 memcpy(ev->dma_data, dma_data, dma_data_length);
341 ev->dma_data_length = dma_data_length;
342 ev->remote_address = remote_address;
343 return signal_event(ev);
347 * Initiate a nice (hopefully) shutdown of Linux. We simply are
348 * going to try and send the init process a SIGINT signal. If
349 * this fails (why?), we'll simply force it off in a not-so-nice
352 static int shutdown(void)
354 int rc = kill_proc(1, SIGINT, 1);
357 printk(KERN_ALERT "mf.c: SIGINT to init failed (%d), "
358 "hard shutdown commencing\n", rc);
361 printk(KERN_INFO "mf.c: init has been successfully notified "
362 "to proceed with shutdown\n");
367 * The primary partition VSP object is sending us a new
368 * event flow. Handle it...
370 static void intReceived(struct IoMFLpEvent *event)
373 struct pending_event *two = NULL;
375 /* ack the interrupt */
376 event->hp_lp_event.xRc = HvLpEvent_Rc_Good;
377 HvCallEvent_ackLpEvent(&event->hp_lp_event);
379 /* process interrupt */
380 switch (event->hp_lp_event.xSubtype) {
381 case 0: /* CE message */
382 switch (event->data.ce_msg.ce_msg[3]) {
383 case 0x5B: /* power control notification */
384 if ((event->data.ce_msg.ce_msg[5] & 0x20) != 0) {
385 printk(KERN_INFO "mf.c: Commencing partition shutdown\n");
387 signal_ce_msg("\x00\x00\x00\xDB\x00\x00\x00\x00\x00\x00\x00\x00", NULL);
390 case 0xC0: /* get time */
391 if ((pending_event_head == NULL) ||
392 (pending_event_head->event.data.ce_msg.ce_msg[3]
396 if (pending_event_head->event.data.ce_msg.completion != 0) {
397 CeMsgCompleteHandler handler = pending_event_head->event.data.ce_msg.completion->handler;
398 void *token = pending_event_head->event.data.ce_msg.completion->token;
401 (*handler)(token, &(event->data.ce_msg));
406 /* remove from queue */
410 spin_lock_irqsave(&pending_event_spinlock, flags);
411 if (pending_event_head != NULL) {
412 struct pending_event *oldHead =
415 pending_event_head = pending_event_head->next;
416 two = pending_event_head;
417 free_pending_event(oldHead);
419 spin_unlock_irqrestore(&pending_event_spinlock, flags);
422 /* send next waiting event */
426 case 1: /* IT sys shutdown */
427 printk(KERN_INFO "mf.c: Commencing system shutdown\n");
434 * The primary partition VSP object is acknowledging the receipt
435 * of a flow we sent to them. If there are other flows queued
436 * up, we must send another one now...
438 static void ackReceived(struct IoMFLpEvent *event)
441 struct pending_event * two = NULL;
442 unsigned long freeIt = 0;
444 /* handle current event */
445 if (pending_event_head != NULL) {
446 switch (event->hp_lp_event.xSubtype) {
448 if (event->data.ce_msg.ce_msg[3] == 0x40) {
449 if (event->data.ce_msg.ce_msg[2] != 0) {
451 if (pending_event_head->event.data.ce_msg.completion
453 CeMsgCompleteHandler handler = pending_event_head->event.data.ce_msg.completion->handler;
454 void *token = pending_event_head->event.data.ce_msg.completion->token;
457 (*handler)(token, &(event->data.ce_msg));
463 case 4: /* allocate */
464 case 5: /* deallocate */
465 if (pending_event_head->hdlr != NULL) {
466 union safe_cast mySafeCast;
468 mySafeCast.ptr_as_u64 = event->hp_lp_event.xCorrelationToken;
469 (*pending_event_head->hdlr)(mySafeCast.ptr, event->data.alloc.count);
475 struct VspRspData *rsp = (struct VspRspData *)event->data.vsp_cmd.token.ptr;
478 if (rsp->response != NULL)
479 memcpy(rsp->response, &(event->data.vsp_cmd), sizeof(event->data.vsp_cmd));
482 printk(KERN_ERR "mf.c: no rsp\n");
489 printk(KERN_ERR "mf.c: stack empty for receiving ack\n");
491 /* remove from queue */
492 spin_lock_irqsave(&pending_event_spinlock, flags);
493 if ((pending_event_head != NULL) && (freeIt == 1)) {
494 struct pending_event *oldHead = pending_event_head;
496 pending_event_head = pending_event_head->next;
497 two = pending_event_head;
498 free_pending_event(oldHead);
500 spin_unlock_irqrestore(&pending_event_spinlock, flags);
502 /* send next waiting event */
508 * This is the generic event handler we are registering with
509 * the Hypervisor. Ensure the flows are for us, and then
510 * parse it enough to know if it is an interrupt or an
513 static void hvHandler(struct HvLpEvent *event, struct pt_regs *regs)
515 if ((event != NULL) && (event->xType == HvLpEvent_Type_MachineFac)) {
516 switch(event->xFlags.xFunction) {
517 case HvLpEvent_Function_Ack:
518 ackReceived((struct IoMFLpEvent *)event);
520 case HvLpEvent_Function_Int:
521 intReceived((struct IoMFLpEvent *)event);
524 printk(KERN_ERR "mf.c: non ack/int event received\n");
528 printk(KERN_ERR "mf.c: alien event received\n");
532 * Global kernel interface to allocate and seed events into the
535 void mf_allocateLpEvents(HvLpIndex targetLp, HvLpEvent_Type type,
536 unsigned size, unsigned count, MFCompleteHandler hdlr,
539 struct pending_event *ev = new_pending_event();
545 union safe_cast mine;
547 mine.ptr = userToken;
548 ev->event.hp_lp_event.xSubtype = 4;
549 ev->event.hp_lp_event.xCorrelationToken = mine.ptr_as_u64;
550 ev->event.hp_lp_event.x.xSubtypeData =
551 subtype_data('M', 'F', 'M', 'A');
552 ev->event.data.alloc.target_lp = targetLp;
553 ev->event.data.alloc.type = type;
554 ev->event.data.alloc.size = size;
555 ev->event.data.alloc.count = count;
557 rc = signal_event(ev);
559 if ((rc != 0) && (hdlr != NULL))
560 (*hdlr)(userToken, rc);
562 EXPORT_SYMBOL(mf_allocateLpEvents);
565 * Global kernel interface to unseed and deallocate events already in
568 void mf_deallocateLpEvents(HvLpIndex targetLp, HvLpEvent_Type type,
569 unsigned count, MFCompleteHandler hdlr, void *userToken)
571 struct pending_event *ev = new_pending_event();
577 union safe_cast mine;
579 mine.ptr = userToken;
580 ev->event.hp_lp_event.xSubtype = 5;
581 ev->event.hp_lp_event.xCorrelationToken = mine.ptr_as_u64;
582 ev->event.hp_lp_event.x.xSubtypeData =
583 subtype_data('M', 'F', 'M', 'D');
584 ev->event.data.alloc.target_lp = targetLp;
585 ev->event.data.alloc.type = type;
586 ev->event.data.alloc.count = count;
588 rc = signal_event(ev);
590 if ((rc != 0) && (hdlr != NULL))
591 (*hdlr)(userToken, rc);
593 EXPORT_SYMBOL(mf_deallocateLpEvents);
596 * Global kernel interface to tell the VSP object in the primary
597 * partition to power this partition off.
599 void mf_powerOff(void)
601 printk(KERN_INFO "mf.c: Down it goes...\n");
602 signal_ce_msg("\x00\x00\x00\x4D\x00\x00\x00\x00\x00\x00\x00\x00", NULL);
607 * Global kernel interface to tell the VSP object in the primary
608 * partition to reboot this partition.
612 printk(KERN_INFO "mf.c: Preparing to bounce...\n");
613 signal_ce_msg("\x00\x00\x00\x4E\x00\x00\x00\x00\x00\x00\x00\x00", NULL);
618 * Display a single word SRC onto the VSP control panel.
620 void mf_displaySrc(u32 word)
624 memcpy(ce, "\x00\x00\x00\x4A\x00\x00\x00\x01\x00\x00\x00\x00", 12);
629 signal_ce_msg(ce, NULL);
633 * Display a single word SRC of the form "PROGXXXX" on the VSP control panel.
635 void mf_displayProgress(u16 value)
640 memcpy(ce, "\x00\x00\x04\x4A\x00\x00\x00\x48\x00\x00\x00\x00", 12);
641 memcpy(src, "\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00"
642 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
643 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
644 "\x00\x00\x00\x00PROGxxxx ",
647 src[7] = value & 255;
648 src[44] = "0123456789ABCDEF"[(value >> 12) & 15];
649 src[45] = "0123456789ABCDEF"[(value >> 8) & 15];
650 src[46] = "0123456789ABCDEF"[(value >> 4) & 15];
651 src[47] = "0123456789ABCDEF"[value & 15];
652 dma_and_signal_ce_msg(ce, NULL, src, sizeof(src), 9 * 64 * 1024);
656 * Clear the VSP control panel. Used to "erase" an SRC that was
657 * previously displayed.
659 void mf_clearSrc(void)
661 signal_ce_msg("\x00\x00\x00\x4B\x00\x00\x00\x00\x00\x00\x00\x00", NULL);
665 * Initialization code here.
672 spin_lock_init(&pending_event_spinlock);
674 i < sizeof(pending_event_prealloc) / sizeof(*pending_event_prealloc);
676 free_pending_event(&pending_event_prealloc[i]);
677 HvLpEvent_registerHandler(HvLpEvent_Type_MachineFac, &hvHandler);
679 /* virtual continue ack */
680 signal_ce_msg("\x00\x00\x00\x57\x00\x00\x00\x00\x00\x00\x00\x00", NULL);
682 /* initialization complete */
683 printk(KERN_NOTICE "mf.c: iSeries Linux LPAR Machine Facilities initialized\n");
686 void mf_setSide(char side)
689 struct VspCmdData myVspCmd;
691 memset(&myVspCmd, 0, sizeof(myVspCmd));
693 case 'A': newSide = 0;
695 case 'B': newSide = 1;
697 case 'C': newSide = 2;
699 default: newSide = 3;
702 myVspCmd.sub_data.ipl_type = newSide;
705 (void)signal_vsp_instruction(&myVspCmd);
708 char mf_getSide(void)
710 char returnValue = ' ';
712 struct VspCmdData myVspCmd;
714 memset(&myVspCmd, 0, sizeof(myVspCmd));
716 myVspCmd.sub_data.ipl_type = 0;
718 rc = signal_vsp_instruction(&myVspCmd);
723 if (myVspCmd.result_code == 0) {
724 switch (myVspCmd.sub_data.ipl_type) {
725 case 0: returnValue = 'A';
727 case 1: returnValue = 'B';
729 case 2: returnValue = 'C';
731 default: returnValue = 'D';
738 void mf_getSrcHistory(char *buffer, int size)
741 struct IplTypeReturnStuff returnStuff;
742 struct pending_event *ev = new_pending_event();
746 pages[0] = kmalloc(4096, GFP_ATOMIC);
747 pages[1] = kmalloc(4096, GFP_ATOMIC);
748 pages[2] = kmalloc(4096, GFP_ATOMIC);
749 pages[3] = kmalloc(4096, GFP_ATOMIC);
750 if ((ev == NULL) || (pages[0] == NULL) || (pages[1] == NULL)
751 || (pages[2] == NULL) || (pages[3] == NULL))
754 returnStuff.xType = 0;
756 returnStuff.xDone = 0;
757 ev->event.hp_lp_event.xSubtype = 6;
758 ev->event.hp_lp_event.x.xSubtypeData =
759 subtype_data('M', 'F', 'V', 'I');
760 ev->event.data.vsp_cmd.xEvent = &returnStuff;
761 ev->event.data.vsp_cmd.cmd = 4;
762 ev->event.data.vsp_cmd.lp_index = HvLpConfig_getLpIndex();
763 ev->event.data.vsp_cmd.result_code = 0xFF;
764 ev->event.data.vsp_cmd.reserved = 0;
765 ev->event.data.vsp_cmd.sub_data.page[0] = ISERIES_HV_ADDR(pages[0]);
766 ev->event.data.vsp_cmd.sub_data.page[1] = ISERIES_HV_ADDR(pages[1]);
767 ev->event.data.vsp_cmd.sub_data.page[2] = ISERIES_HV_ADDR(pages[2]);
768 ev->event.data.vsp_cmd.sub_data.page[3] = ISERIES_HV_ADDR(pages[3]);
770 if (signal_event(ev) != 0)
773 while (returnStuff.xDone != 1)
775 if (returnStuff.xRc == 0)
776 memcpy(buffer, pages[0], size);
784 void mf_setCmdLine(const char *cmdline, int size, u64 side)
786 struct VspCmdData myVspCmd;
787 dma_addr_t dma_addr = 0;
788 char *page = dma_alloc_coherent(iSeries_vio_dev, size, &dma_addr,
792 printk(KERN_ERR "mf.c: couldn't allocate memory to set command line\n");
796 copy_from_user(page, cmdline, size);
798 memset(&myVspCmd, 0, sizeof(myVspCmd));
800 myVspCmd.sub_data.kern.token = dma_addr;
801 myVspCmd.sub_data.kern.address_type = HvLpDma_AddressType_TceIndex;
802 myVspCmd.sub_data.kern.side = side;
803 myVspCmd.sub_data.kern.length = size;
805 (void)signal_vsp_instruction(&myVspCmd);
807 dma_free_coherent(iSeries_vio_dev, size, page, dma_addr);
810 int mf_getCmdLine(char *cmdline, int *size, u64 side)
812 struct VspCmdData myVspCmd;
817 dma_addr = dma_map_single(iSeries_vio_dev, cmdline, len,
819 memset(cmdline, 0, len);
820 memset(&myVspCmd, 0, sizeof(myVspCmd));
822 myVspCmd.sub_data.kern.token = dma_addr;
823 myVspCmd.sub_data.kern.address_type = HvLpDma_AddressType_TceIndex;
824 myVspCmd.sub_data.kern.side = side;
825 myVspCmd.sub_data.kern.length = len;
827 rc = signal_vsp_instruction(&myVspCmd);
830 if (myVspCmd.result_code == 0)
831 len = myVspCmd.sub_data.length_out;
834 memcpy(cmdline, "Bad cmdline", 11);
838 dma_unmap_single(iSeries_vio_dev, dma_addr, *size, DMA_FROM_DEVICE);
844 int mf_setVmlinuxChunk(const char *buffer, int size, int offset, u64 side)
846 struct VspCmdData myVspCmd;
848 dma_addr_t dma_addr = 0;
849 char *page = dma_alloc_coherent(iSeries_vio_dev, size, &dma_addr,
853 printk(KERN_ERR "mf.c: couldn't allocate memory to set vmlinux chunk\n");
857 copy_from_user(page, buffer, size);
858 memset(&myVspCmd, 0, sizeof(myVspCmd));
861 myVspCmd.sub_data.kern.token = dma_addr;
862 myVspCmd.sub_data.kern.address_type = HvLpDma_AddressType_TceIndex;
863 myVspCmd.sub_data.kern.side = side;
864 myVspCmd.sub_data.kern.offset = offset;
865 myVspCmd.sub_data.kern.length = size;
867 rc = signal_vsp_instruction(&myVspCmd);
869 if (myVspCmd.result_code == 0)
875 dma_free_coherent(iSeries_vio_dev, size, page, dma_addr);
880 int mf_getVmlinuxChunk(char *buffer, int *size, int offset, u64 side)
882 struct VspCmdData myVspCmd;
887 dma_addr = dma_map_single(iSeries_vio_dev, buffer, len,
889 memset(buffer, 0, len);
890 memset(&myVspCmd, 0, sizeof(myVspCmd));
892 myVspCmd.sub_data.kern.token = dma_addr;
893 myVspCmd.sub_data.kern.address_type = HvLpDma_AddressType_TceIndex;
894 myVspCmd.sub_data.kern.side = side;
895 myVspCmd.sub_data.kern.offset = offset;
896 myVspCmd.sub_data.kern.length = len;
898 rc = signal_vsp_instruction(&myVspCmd);
900 if (myVspCmd.result_code == 0)
901 *size = myVspCmd.sub_data.length_out;
906 dma_unmap_single(iSeries_vio_dev, dma_addr, len, DMA_FROM_DEVICE);
911 int mf_setRtcTime(unsigned long time)
917 return mf_setRtc(&tm);
921 struct completion com;
922 struct CeMsgData xCeMsg;
926 void getRtcTimeComplete(void * token, struct CeMsgData *ceMsg)
928 struct RtcTimeData *rtc = (struct RtcTimeData *)token;
930 memcpy(&(rtc->xCeMsg), ceMsg, sizeof(rtc->xCeMsg));
935 static unsigned long lastsec = 1;
937 int mf_getRtcTime(unsigned long *time)
939 u32 dataWord1 = *((u32 *)(&xSpCommArea.xBcdTimeAtIplStart));
940 u32 dataWord2 = *(((u32 *)&(xSpCommArea.xBcdTimeAtIplStart)) + 1);
942 int year1 = (dataWord1 >> 24) & 0x000000FF;
943 int year2 = (dataWord1 >> 16) & 0x000000FF;
944 int sec = (dataWord1 >> 8) & 0x000000FF;
945 int min = dataWord1 & 0x000000FF;
946 int hour = (dataWord2 >> 24) & 0x000000FF;
947 int day = (dataWord2 >> 8) & 0x000000FF;
948 int mon = dataWord2 & 0x000000FF;
957 year = year1 * 100 + year2;
959 *time = mktime(year, mon, day, hour, min, sec);
960 *time += (jiffies / HZ);
963 * Now THIS is a nasty hack!
964 * It ensures that the first two calls to mf_getRtcTime get different
965 * answers. That way the loop in init_time (time.c) will not think
966 * the clock is stuck.
975 int mf_getRtc(struct rtc_time *tm)
977 struct CeMsgCompleteData ceComplete;
978 struct RtcTimeData rtcData;
981 memset(&ceComplete, 0, sizeof(ceComplete));
982 memset(&rtcData, 0, sizeof(rtcData));
983 init_completion(&rtcData.com);
984 ceComplete.handler = &getRtcTimeComplete;
985 ceComplete.token = (void *)&rtcData;
986 rc = signal_ce_msg("\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00",
989 wait_for_completion(&rtcData.com);
991 if (rtcData.xRc == 0) {
992 if ((rtcData.xCeMsg.ce_msg[2] == 0xa9) ||
993 (rtcData.xCeMsg.ce_msg[2] == 0xaf)) {
994 /* TOD clock is not set */
1004 u32 dataWord1 = *((u32 *)(rtcData.xCeMsg.ce_msg+4));
1005 u32 dataWord2 = *((u32 *)(rtcData.xCeMsg.ce_msg+8));
1006 u8 year = (dataWord1 >> 16) & 0x000000FF;
1007 u8 sec = (dataWord1 >> 8) & 0x000000FF;
1008 u8 min = dataWord1 & 0x000000FF;
1009 u8 hour = (dataWord2 >> 24) & 0x000000FF;
1010 u8 day = (dataWord2 >> 8) & 0x000000FF;
1011 u8 mon = dataWord2 & 0x000000FF;
1048 int mf_setRtc(struct rtc_time * tm)
1050 char ceTime[12] = "\x00\x00\x00\x41\x00\x00\x00\x00\x00\x00\x00\x00";
1051 u8 day, mon, hour, min, sec, y1, y2;
1054 year = 1900 + tm->tm_year;
1062 mon = tm->tm_mon + 1;
1080 return signal_ce_msg(ceTime, NULL);