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/export.h>
34 #include <linux/proc_fs.h>
35 #include <linux/dma-mapping.h>
36 #include <linux/bcd.h>
37 #include <linux/rtc.h>
38 #include <linux/slab.h>
41 #include <asm/uaccess.h>
43 #include <asm/abs_addr.h>
44 #include <asm/firmware.h>
45 #include <asm/iseries/mf.h>
46 #include <asm/iseries/hv_lp_config.h>
47 #include <asm/iseries/hv_lp_event.h>
48 #include <asm/iseries/it_lp_queue.h>
52 static int mf_initialized;
55 * This is the structure layout for the Machine Facilities LPAR event
65 u64 state; /* GetStateOut */
66 u64 ipl_type; /* GetIplTypeOut, Function02SelectIplTypeIn */
67 u64 ipl_mode; /* GetIplModeOut, Function02SelectIplModeIn */
68 u64 page[4]; /* GetSrcHistoryIn */
69 u64 flag; /* GetAutoIplWhenPrimaryIplsOut,
70 SetAutoIplWhenPrimaryIplsIn,
71 WhiteButtonPowerOffIn,
72 Function08FastPowerOffIn,
73 IsSpcnRackPowerIncompleteOut */
80 } kern; /* SetKernelImageIn, GetKernelImageIn,
81 SetKernelCmdLineIn, GetKernelCmdLineIn */
82 u32 length_out; /* GetKernelImageOut, GetKernelCmdLineOut */
88 struct completion com;
89 struct vsp_cmd_data *response;
103 typedef void (*ce_msg_comp_hdlr)(void *token, struct ce_msg_data *vsp_cmd_rsp);
105 struct ce_msg_comp_data {
106 ce_msg_comp_hdlr handler;
113 struct ce_msg_comp_data *completion;
116 struct io_mf_lp_event {
117 struct HvLpEvent hp_lp_event;
118 u16 subtype_result_code;
122 struct alloc_data alloc;
123 struct ce_msg_data ce_msg;
124 struct vsp_cmd_data vsp_cmd;
128 #define subtype_data(a, b, c, d) \
129 (((a) << 24) + ((b) << 16) + ((c) << 8) + (d))
132 * All outgoing event traffic is kept on a FIFO queue. The first
133 * pointer points to the one that is outstanding, and all new
134 * requests get stuck on the end. Also, we keep a certain number of
135 * preallocated pending events so that we can operate very early in
136 * the boot up sequence (before kmalloc is ready).
138 struct pending_event {
139 struct pending_event *next;
140 struct io_mf_lp_event event;
141 MFCompleteHandler hdlr;
143 unsigned dma_data_length;
144 unsigned remote_address;
146 static spinlock_t pending_event_spinlock;
147 static struct pending_event *pending_event_head;
148 static struct pending_event *pending_event_tail;
149 static struct pending_event *pending_event_avail;
150 #define PENDING_EVENT_PREALLOC_LEN 16
151 static struct pending_event pending_event_prealloc[PENDING_EVENT_PREALLOC_LEN];
154 * Put a pending event onto the available queue, so it can get reused.
155 * Attention! You must have the pending_event_spinlock before calling!
157 static void free_pending_event(struct pending_event *ev)
160 ev->next = pending_event_avail;
161 pending_event_avail = ev;
166 * Enqueue the outbound event onto the stack. If the queue was
167 * empty to begin with, we must also issue it via the Hypervisor
168 * interface. There is a section of code below that will touch
169 * the first stack pointer without the protection of the pending_event_spinlock.
170 * This is OK, because we know that nobody else will be modifying
171 * the first pointer when we do this.
173 static int signal_event(struct pending_event *ev)
178 struct pending_event *ev1;
181 /* enqueue the event */
184 spin_lock_irqsave(&pending_event_spinlock, flags);
185 if (pending_event_head == NULL)
186 pending_event_head = ev;
189 pending_event_tail->next = ev;
191 pending_event_tail = ev;
192 spin_unlock_irqrestore(&pending_event_spinlock, flags);
199 /* any DMA data to send beforehand? */
200 if (pending_event_head->dma_data_length > 0)
201 HvCallEvent_dmaToSp(pending_event_head->dma_data,
202 pending_event_head->remote_address,
203 pending_event_head->dma_data_length,
204 HvLpDma_Direction_LocalToRemote);
206 hv_rc = HvCallEvent_signalLpEvent(
207 &pending_event_head->event.hp_lp_event);
208 if (hv_rc != HvLpEvent_Rc_Good) {
209 printk(KERN_ERR "mf.c: HvCallEvent_signalLpEvent() "
210 "failed with %d\n", (int)hv_rc);
212 spin_lock_irqsave(&pending_event_spinlock, flags);
213 ev1 = pending_event_head;
214 pending_event_head = pending_event_head->next;
215 if (pending_event_head != NULL)
217 spin_unlock_irqrestore(&pending_event_spinlock, flags);
221 else if (ev1->hdlr != NULL)
222 (*ev1->hdlr)((void *)ev1->event.hp_lp_event.xCorrelationToken, -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 primary_lp = 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));
257 memset(ev, 0, sizeof(struct pending_event));
258 hev = &ev->event.hp_lp_event;
259 hev->flags = HV_LP_EVENT_VALID | HV_LP_EVENT_DO_ACK | HV_LP_EVENT_INT;
260 hev->xType = HvLpEvent_Type_MachineFac;
261 hev->xSourceLp = HvLpConfig_getLpIndex();
262 hev->xTargetLp = primary_lp;
263 hev->xSizeMinus1 = sizeof(ev->event) - 1;
264 hev->xRc = HvLpEvent_Rc_Good;
265 hev->xSourceInstanceId = HvCallEvent_getSourceLpInstanceId(primary_lp,
266 HvLpEvent_Type_MachineFac);
267 hev->xTargetInstanceId = HvCallEvent_getTargetLpInstanceId(primary_lp,
268 HvLpEvent_Type_MachineFac);
273 static int __maybe_unused
274 signal_vsp_instruction(struct vsp_cmd_data *vsp_cmd)
276 struct pending_event *ev = new_pending_event();
278 struct vsp_rsp_data response;
283 init_completion(&response.com);
284 response.response = vsp_cmd;
285 ev->event.hp_lp_event.xSubtype = 6;
286 ev->event.hp_lp_event.x.xSubtypeData =
287 subtype_data('M', 'F', 'V', 'I');
288 ev->event.data.vsp_cmd.token = (u64)&response;
289 ev->event.data.vsp_cmd.cmd = vsp_cmd->cmd;
290 ev->event.data.vsp_cmd.lp_index = HvLpConfig_getLpIndex();
291 ev->event.data.vsp_cmd.result_code = 0xFF;
292 ev->event.data.vsp_cmd.reserved = 0;
293 memcpy(&(ev->event.data.vsp_cmd.sub_data),
294 &(vsp_cmd->sub_data), sizeof(vsp_cmd->sub_data));
297 rc = signal_event(ev);
299 wait_for_completion(&response.com);
305 * Send a 12-byte CE message to the primary partition VSP object
307 static int signal_ce_msg(char *ce_msg, struct ce_msg_comp_data *completion)
309 struct pending_event *ev = new_pending_event();
314 ev->event.hp_lp_event.xSubtype = 0;
315 ev->event.hp_lp_event.x.xSubtypeData =
316 subtype_data('M', 'F', 'C', 'E');
317 memcpy(ev->event.data.ce_msg.ce_msg, ce_msg, 12);
318 ev->event.data.ce_msg.completion = completion;
319 return signal_event(ev);
323 * Send a 12-byte CE message (with no data) to the primary partition VSP object
325 static int signal_ce_msg_simple(u8 ce_op, struct ce_msg_comp_data *completion)
329 memset(ce_msg, 0, sizeof(ce_msg));
331 return signal_ce_msg(ce_msg, completion);
335 * Send a 12-byte CE message and DMA data to the primary partition VSP object
337 static int dma_and_signal_ce_msg(char *ce_msg,
338 struct ce_msg_comp_data *completion, void *dma_data,
339 unsigned dma_data_length, unsigned remote_address)
341 struct pending_event *ev = new_pending_event();
346 ev->event.hp_lp_event.xSubtype = 0;
347 ev->event.hp_lp_event.x.xSubtypeData =
348 subtype_data('M', 'F', 'C', 'E');
349 memcpy(ev->event.data.ce_msg.ce_msg, ce_msg, 12);
350 ev->event.data.ce_msg.completion = completion;
351 memcpy(ev->dma_data, dma_data, dma_data_length);
352 ev->dma_data_length = dma_data_length;
353 ev->remote_address = remote_address;
354 return signal_event(ev);
358 * Initiate a nice (hopefully) shutdown of Linux. We simply are
359 * going to try and send the init process a SIGINT signal. If
360 * this fails (why?), we'll simply force it off in a not-so-nice
363 static int shutdown(void)
365 int rc = kill_cad_pid(SIGINT, 1);
368 printk(KERN_ALERT "mf.c: SIGINT to init failed (%d), "
369 "hard shutdown commencing\n", rc);
372 printk(KERN_INFO "mf.c: init has been successfully notified "
373 "to proceed with shutdown\n");
378 * The primary partition VSP object is sending us a new
379 * event flow. Handle it...
381 static void handle_int(struct io_mf_lp_event *event)
383 struct ce_msg_data *ce_msg_data;
384 struct ce_msg_data *pce_msg_data;
386 struct pending_event *pev;
388 /* ack the interrupt */
389 event->hp_lp_event.xRc = HvLpEvent_Rc_Good;
390 HvCallEvent_ackLpEvent(&event->hp_lp_event);
392 /* process interrupt */
393 switch (event->hp_lp_event.xSubtype) {
394 case 0: /* CE message */
395 ce_msg_data = &event->data.ce_msg;
396 switch (ce_msg_data->ce_msg[3]) {
397 case 0x5B: /* power control notification */
398 if ((ce_msg_data->ce_msg[5] & 0x20) != 0) {
399 printk(KERN_INFO "mf.c: Commencing partition shutdown\n");
401 signal_ce_msg_simple(0xDB, NULL);
404 case 0xC0: /* get time */
405 spin_lock_irqsave(&pending_event_spinlock, flags);
406 pev = pending_event_head;
408 pending_event_head = pending_event_head->next;
409 spin_unlock_irqrestore(&pending_event_spinlock, flags);
412 pce_msg_data = &pev->event.data.ce_msg;
413 if (pce_msg_data->ce_msg[3] != 0x40)
415 if (pce_msg_data->completion != NULL) {
416 ce_msg_comp_hdlr handler =
417 pce_msg_data->completion->handler;
418 void *token = pce_msg_data->completion->token;
421 (*handler)(token, ce_msg_data);
423 spin_lock_irqsave(&pending_event_spinlock, flags);
424 free_pending_event(pev);
425 spin_unlock_irqrestore(&pending_event_spinlock, flags);
426 /* send next waiting event */
427 if (pending_event_head != NULL)
432 case 1: /* IT sys shutdown */
433 printk(KERN_INFO "mf.c: Commencing system shutdown\n");
440 * The primary partition VSP object is acknowledging the receipt
441 * of a flow we sent to them. If there are other flows queued
442 * up, we must send another one now...
444 static void handle_ack(struct io_mf_lp_event *event)
447 struct pending_event *two = NULL;
448 unsigned long free_it = 0;
449 struct ce_msg_data *ce_msg_data;
450 struct ce_msg_data *pce_msg_data;
451 struct vsp_rsp_data *rsp;
453 /* handle current event */
454 if (pending_event_head == NULL) {
455 printk(KERN_ERR "mf.c: stack empty for receiving ack\n");
459 switch (event->hp_lp_event.xSubtype) {
461 ce_msg_data = &event->data.ce_msg;
462 if (ce_msg_data->ce_msg[3] != 0x40) {
466 if (ce_msg_data->ce_msg[2] == 0)
469 pce_msg_data = &pending_event_head->event.data.ce_msg;
470 if (pce_msg_data->completion != NULL) {
471 ce_msg_comp_hdlr handler =
472 pce_msg_data->completion->handler;
473 void *token = pce_msg_data->completion->token;
476 (*handler)(token, ce_msg_data);
479 case 4: /* allocate */
480 case 5: /* deallocate */
481 if (pending_event_head->hdlr != NULL)
482 (*pending_event_head->hdlr)((void *)event->hp_lp_event.xCorrelationToken, event->data.alloc.count);
487 rsp = (struct vsp_rsp_data *)event->data.vsp_cmd.token;
489 printk(KERN_ERR "mf.c: no rsp\n");
492 if (rsp->response != NULL)
493 memcpy(rsp->response, &event->data.vsp_cmd,
494 sizeof(event->data.vsp_cmd));
499 /* remove from queue */
500 spin_lock_irqsave(&pending_event_spinlock, flags);
501 if ((pending_event_head != NULL) && (free_it == 1)) {
502 struct pending_event *oldHead = pending_event_head;
504 pending_event_head = pending_event_head->next;
505 two = pending_event_head;
506 free_pending_event(oldHead);
508 spin_unlock_irqrestore(&pending_event_spinlock, flags);
510 /* send next waiting event */
516 * This is the generic event handler we are registering with
517 * the Hypervisor. Ensure the flows are for us, and then
518 * parse it enough to know if it is an interrupt or an
521 static void hv_handler(struct HvLpEvent *event)
523 if ((event != NULL) && (event->xType == HvLpEvent_Type_MachineFac)) {
524 if (hvlpevent_is_ack(event))
525 handle_ack((struct io_mf_lp_event *)event);
527 handle_int((struct io_mf_lp_event *)event);
529 printk(KERN_ERR "mf.c: alien event received\n");
533 * Global kernel interface to allocate and seed events into the
536 void mf_allocate_lp_events(HvLpIndex target_lp, HvLpEvent_Type type,
537 unsigned size, unsigned count, MFCompleteHandler hdlr,
540 struct pending_event *ev = new_pending_event();
546 ev->event.hp_lp_event.xSubtype = 4;
547 ev->event.hp_lp_event.xCorrelationToken = (u64)user_token;
548 ev->event.hp_lp_event.x.xSubtypeData =
549 subtype_data('M', 'F', 'M', 'A');
550 ev->event.data.alloc.target_lp = target_lp;
551 ev->event.data.alloc.type = type;
552 ev->event.data.alloc.size = size;
553 ev->event.data.alloc.count = count;
555 rc = signal_event(ev);
557 if ((rc != 0) && (hdlr != NULL))
558 (*hdlr)(user_token, rc);
560 EXPORT_SYMBOL(mf_allocate_lp_events);
563 * Global kernel interface to unseed and deallocate events already in
566 void mf_deallocate_lp_events(HvLpIndex target_lp, HvLpEvent_Type type,
567 unsigned count, MFCompleteHandler hdlr, void *user_token)
569 struct pending_event *ev = new_pending_event();
575 ev->event.hp_lp_event.xSubtype = 5;
576 ev->event.hp_lp_event.xCorrelationToken = (u64)user_token;
577 ev->event.hp_lp_event.x.xSubtypeData =
578 subtype_data('M', 'F', 'M', 'D');
579 ev->event.data.alloc.target_lp = target_lp;
580 ev->event.data.alloc.type = type;
581 ev->event.data.alloc.count = count;
583 rc = signal_event(ev);
585 if ((rc != 0) && (hdlr != NULL))
586 (*hdlr)(user_token, rc);
588 EXPORT_SYMBOL(mf_deallocate_lp_events);
591 * Global kernel interface to tell the VSP object in the primary
592 * partition to power this partition off.
594 void mf_power_off(void)
596 printk(KERN_INFO "mf.c: Down it goes...\n");
597 signal_ce_msg_simple(0x4d, NULL);
603 * Global kernel interface to tell the VSP object in the primary
604 * partition to reboot this partition.
606 void mf_reboot(char *cmd)
608 printk(KERN_INFO "mf.c: Preparing to bounce...\n");
609 signal_ce_msg_simple(0x4e, NULL);
615 * Display a single word SRC onto the VSP control panel.
617 void mf_display_src(u32 word)
621 memset(ce, 0, sizeof(ce));
628 signal_ce_msg(ce, NULL);
632 * Display a single word SRC of the form "PROGXXXX" on the VSP control panel.
634 static __init void mf_display_progress_src(u16 value)
639 memcpy(ce, "\x00\x00\x04\x4A\x00\x00\x00\x48\x00\x00\x00\x00", 12);
640 memcpy(src, "\x01\x00\x00\x01\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\x00\x00\x00\x00\x00\x00\x00\x00\x00"
643 "\x00\x00\x00\x00PROGxxxx ",
646 src[7] = value & 255;
647 src[44] = "0123456789ABCDEF"[(value >> 12) & 15];
648 src[45] = "0123456789ABCDEF"[(value >> 8) & 15];
649 src[46] = "0123456789ABCDEF"[(value >> 4) & 15];
650 src[47] = "0123456789ABCDEF"[value & 15];
651 dma_and_signal_ce_msg(ce, NULL, src, sizeof(src), 9 * 64 * 1024);
655 * Clear the VSP control panel. Used to "erase" an SRC that was
656 * previously displayed.
658 static void mf_clear_src(void)
660 signal_ce_msg_simple(0x4b, NULL);
663 void __init mf_display_progress(u16 value)
671 mf_display_progress_src(value);
675 * Initialization code here.
677 void __init mf_init(void)
681 spin_lock_init(&pending_event_spinlock);
683 for (i = 0; i < PENDING_EVENT_PREALLOC_LEN; i++)
684 free_pending_event(&pending_event_prealloc[i]);
686 HvLpEvent_registerHandler(HvLpEvent_Type_MachineFac, &hv_handler);
688 /* virtual continue ack */
689 signal_ce_msg_simple(0x57, NULL);
694 printk(KERN_NOTICE "mf.c: iSeries Linux LPAR Machine Facilities "
698 struct rtc_time_data {
699 struct completion com;
700 struct ce_msg_data ce_msg;
704 static void get_rtc_time_complete(void *token, struct ce_msg_data *ce_msg)
706 struct rtc_time_data *rtc = token;
708 memcpy(&rtc->ce_msg, ce_msg, sizeof(rtc->ce_msg));
713 static int mf_set_rtc(struct rtc_time *tm)
716 u8 day, mon, hour, min, sec, y1, y2;
719 year = 1900 + tm->tm_year;
727 mon = tm->tm_mon + 1;
731 hour = bin2bcd(hour);
737 memset(ce_time, 0, sizeof(ce_time));
747 return signal_ce_msg(ce_time, NULL);
750 static int rtc_set_tm(int rc, u8 *ce_msg, struct rtc_time *tm)
765 if ((ce_msg[2] == 0xa9) ||
766 (ce_msg[2] == 0xaf)) {
767 /* TOD clock is not set */
786 hour = bcd2bin(hour);
789 year = bcd2bin(year);
805 static int mf_get_rtc(struct rtc_time *tm)
807 struct ce_msg_comp_data ce_complete;
808 struct rtc_time_data rtc_data;
811 memset(&ce_complete, 0, sizeof(ce_complete));
812 memset(&rtc_data, 0, sizeof(rtc_data));
813 init_completion(&rtc_data.com);
814 ce_complete.handler = &get_rtc_time_complete;
815 ce_complete.token = &rtc_data;
816 rc = signal_ce_msg_simple(0x40, &ce_complete);
819 wait_for_completion(&rtc_data.com);
820 return rtc_set_tm(rtc_data.rc, rtc_data.ce_msg.ce_msg, tm);
823 struct boot_rtc_time_data {
825 struct ce_msg_data ce_msg;
829 static void get_boot_rtc_time_complete(void *token, struct ce_msg_data *ce_msg)
831 struct boot_rtc_time_data *rtc = token;
833 memcpy(&rtc->ce_msg, ce_msg, sizeof(rtc->ce_msg));
838 static int mf_get_boot_rtc(struct rtc_time *tm)
840 struct ce_msg_comp_data ce_complete;
841 struct boot_rtc_time_data rtc_data;
844 memset(&ce_complete, 0, sizeof(ce_complete));
845 memset(&rtc_data, 0, sizeof(rtc_data));
847 ce_complete.handler = &get_boot_rtc_time_complete;
848 ce_complete.token = &rtc_data;
849 rc = signal_ce_msg_simple(0x40, &ce_complete);
852 /* We need to poll here as we are not yet taking interrupts */
853 while (rtc_data.busy) {
854 if (hvlpevent_is_pending())
855 process_hvlpevents();
857 return rtc_set_tm(rtc_data.rc, rtc_data.ce_msg.ce_msg, tm);
860 #ifdef CONFIG_PROC_FS
861 static int mf_cmdline_proc_show(struct seq_file *m, void *v)
864 struct vsp_cmd_data vsp_cmd;
868 /* The HV appears to return no more than 256 bytes of command line */
869 page = kmalloc(256, GFP_KERNEL);
873 dma_addr = iseries_hv_map(page, 256, DMA_FROM_DEVICE);
874 if (dma_addr == DMA_ERROR_CODE) {
878 memset(page, 0, 256);
879 memset(&vsp_cmd, 0, sizeof(vsp_cmd));
881 vsp_cmd.sub_data.kern.token = dma_addr;
882 vsp_cmd.sub_data.kern.address_type = HvLpDma_AddressType_TceIndex;
883 vsp_cmd.sub_data.kern.side = (u64)m->private;
884 vsp_cmd.sub_data.kern.length = 256;
886 rc = signal_vsp_instruction(&vsp_cmd);
887 iseries_hv_unmap(dma_addr, 256, DMA_FROM_DEVICE);
892 if (vsp_cmd.result_code != 0) {
897 while (p - page < 256) {
898 if (*p == '\0' || *p == '\n') {
905 seq_write(m, page, p - page);
910 static int mf_cmdline_proc_open(struct inode *inode, struct file *file)
912 return single_open(file, mf_cmdline_proc_show, PDE(inode)->data);
916 static int mf_getVmlinuxChunk(char *buffer, int *size, int offset, u64 side)
918 struct vsp_cmd_data vsp_cmd;
923 dma_addr = iseries_hv_map(buffer, len, DMA_FROM_DEVICE);
924 memset(buffer, 0, len);
925 memset(&vsp_cmd, 0, sizeof(vsp_cmd));
927 vsp_cmd.sub_data.kern.token = dma_addr;
928 vsp_cmd.sub_data.kern.address_type = HvLpDma_AddressType_TceIndex;
929 vsp_cmd.sub_data.kern.side = side;
930 vsp_cmd.sub_data.kern.offset = offset;
931 vsp_cmd.sub_data.kern.length = len;
933 rc = signal_vsp_instruction(&vsp_cmd);
935 if (vsp_cmd.result_code == 0)
936 *size = vsp_cmd.sub_data.length_out;
941 iseries_hv_unmap(dma_addr, len, DMA_FROM_DEVICE);
946 static int proc_mf_dump_vmlinux(char *page, char **start, off_t off,
947 int count, int *eof, void *data)
949 int sizeToGet = count;
951 if (!capable(CAP_SYS_ADMIN))
954 if (mf_getVmlinuxChunk(page, &sizeToGet, off, (u64)data) == 0) {
955 if (sizeToGet != 0) {
967 static int mf_side_proc_show(struct seq_file *m, void *v)
969 char mf_current_side = ' ';
970 struct vsp_cmd_data vsp_cmd;
972 memset(&vsp_cmd, 0, sizeof(vsp_cmd));
974 vsp_cmd.sub_data.ipl_type = 0;
977 if (signal_vsp_instruction(&vsp_cmd) == 0) {
978 if (vsp_cmd.result_code == 0) {
979 switch (vsp_cmd.sub_data.ipl_type) {
980 case 0: mf_current_side = 'A';
982 case 1: mf_current_side = 'B';
984 case 2: mf_current_side = 'C';
986 default: mf_current_side = 'D';
992 seq_printf(m, "%c\n", mf_current_side);
996 static int mf_side_proc_open(struct inode *inode, struct file *file)
998 return single_open(file, mf_side_proc_show, NULL);
1001 static ssize_t mf_side_proc_write(struct file *file, const char __user *buffer,
1002 size_t count, loff_t *pos)
1006 struct vsp_cmd_data vsp_cmd;
1008 if (!capable(CAP_SYS_ADMIN))
1014 if (get_user(side, buffer))
1018 case 'A': newSide = 0;
1020 case 'B': newSide = 1;
1022 case 'C': newSide = 2;
1024 case 'D': newSide = 3;
1027 printk(KERN_ERR "mf_proc.c: proc_mf_change_side: invalid side\n");
1031 memset(&vsp_cmd, 0, sizeof(vsp_cmd));
1032 vsp_cmd.sub_data.ipl_type = newSide;
1035 (void)signal_vsp_instruction(&vsp_cmd);
1040 static const struct file_operations mf_side_proc_fops = {
1041 .owner = THIS_MODULE,
1042 .open = mf_side_proc_open,
1044 .llseek = seq_lseek,
1045 .release = single_release,
1046 .write = mf_side_proc_write,
1049 static int mf_src_proc_show(struct seq_file *m, void *v)
1054 static int mf_src_proc_open(struct inode *inode, struct file *file)
1056 return single_open(file, mf_src_proc_show, NULL);
1059 static ssize_t mf_src_proc_write(struct file *file, const char __user *buffer,
1060 size_t count, loff_t *pos)
1064 if (!capable(CAP_SYS_ADMIN))
1067 if ((count < 4) && (count != 1)) {
1068 printk(KERN_ERR "mf_proc: invalid src\n");
1072 if (count > (sizeof(stkbuf) - 1))
1073 count = sizeof(stkbuf) - 1;
1074 if (copy_from_user(stkbuf, buffer, count))
1077 if ((count == 1) && (*stkbuf == '\0'))
1080 mf_display_src(*(u32 *)stkbuf);
1085 static const struct file_operations mf_src_proc_fops = {
1086 .owner = THIS_MODULE,
1087 .open = mf_src_proc_open,
1089 .llseek = seq_lseek,
1090 .release = single_release,
1091 .write = mf_src_proc_write,
1094 static ssize_t mf_cmdline_proc_write(struct file *file, const char __user *buffer,
1095 size_t count, loff_t *pos)
1097 void *data = PDE(file->f_path.dentry->d_inode)->data;
1098 struct vsp_cmd_data vsp_cmd;
1099 dma_addr_t dma_addr;
1103 if (!capable(CAP_SYS_ADMIN))
1107 page = iseries_hv_alloc(count, &dma_addr, GFP_ATOMIC);
1113 if (copy_from_user(page, buffer, count))
1116 memset(&vsp_cmd, 0, sizeof(vsp_cmd));
1118 vsp_cmd.sub_data.kern.token = dma_addr;
1119 vsp_cmd.sub_data.kern.address_type = HvLpDma_AddressType_TceIndex;
1120 vsp_cmd.sub_data.kern.side = (u64)data;
1121 vsp_cmd.sub_data.kern.length = count;
1123 (void)signal_vsp_instruction(&vsp_cmd);
1127 iseries_hv_free(count, page, dma_addr);
1132 static const struct file_operations mf_cmdline_proc_fops = {
1133 .owner = THIS_MODULE,
1134 .open = mf_cmdline_proc_open,
1136 .llseek = seq_lseek,
1137 .release = single_release,
1138 .write = mf_cmdline_proc_write,
1141 static ssize_t proc_mf_change_vmlinux(struct file *file,
1142 const char __user *buf,
1143 size_t count, loff_t *ppos)
1145 struct proc_dir_entry *dp = PDE(file->f_path.dentry->d_inode);
1147 dma_addr_t dma_addr;
1149 struct vsp_cmd_data vsp_cmd;
1152 if (!capable(CAP_SYS_ADMIN))
1156 page = iseries_hv_alloc(count, &dma_addr, GFP_ATOMIC);
1159 printk(KERN_ERR "mf.c: couldn't allocate memory to set vmlinux chunk\n");
1163 if (copy_from_user(page, buf, count))
1166 memset(&vsp_cmd, 0, sizeof(vsp_cmd));
1168 vsp_cmd.sub_data.kern.token = dma_addr;
1169 vsp_cmd.sub_data.kern.address_type = HvLpDma_AddressType_TceIndex;
1170 vsp_cmd.sub_data.kern.side = (u64)dp->data;
1171 vsp_cmd.sub_data.kern.offset = *ppos;
1172 vsp_cmd.sub_data.kern.length = count;
1174 rc = signal_vsp_instruction(&vsp_cmd);
1178 if (vsp_cmd.result_code != 0)
1184 iseries_hv_free(count, page, dma_addr);
1189 static const struct file_operations proc_vmlinux_operations = {
1190 .write = proc_mf_change_vmlinux,
1191 .llseek = default_llseek,
1194 static int __init mf_proc_init(void)
1196 struct proc_dir_entry *mf_proc_root;
1197 struct proc_dir_entry *ent;
1198 struct proc_dir_entry *mf;
1202 if (!firmware_has_feature(FW_FEATURE_ISERIES))
1205 mf_proc_root = proc_mkdir("iSeries/mf", NULL);
1210 for (i = 0; i < 4; i++) {
1212 mf = proc_mkdir(name, mf_proc_root);
1216 ent = proc_create_data("cmdline", S_IRUSR|S_IWUSR, mf,
1217 &mf_cmdline_proc_fops, (void *)(long)i);
1221 if (i == 3) /* no vmlinux entry for 'D' */
1224 ent = proc_create_data("vmlinux", S_IFREG|S_IWUSR, mf,
1225 &proc_vmlinux_operations,
1231 ent = proc_create("side", S_IFREG|S_IRUSR|S_IWUSR, mf_proc_root,
1232 &mf_side_proc_fops);
1236 ent = proc_create("src", S_IFREG|S_IRUSR|S_IWUSR, mf_proc_root,
1244 __initcall(mf_proc_init);
1246 #endif /* CONFIG_PROC_FS */
1249 * Get the RTC from the virtual service processor
1250 * This requires flowing LpEvents to the primary partition
1252 void iSeries_get_rtc_time(struct rtc_time *rtc_tm)
1259 * Set the RTC in the virtual service processor
1260 * This requires flowing LpEvents to the primary partition
1262 int iSeries_set_rtc_time(struct rtc_time *tm)
1268 unsigned long iSeries_get_boot_time(void)
1272 mf_get_boot_rtc(&tm);
1273 return mktime(tm.tm_year + 1900, tm.tm_mon, tm.tm_mday,
1274 tm.tm_hour, tm.tm_min, tm.tm_sec);