3 * Copyright (C) 2001 Troy D. Armstrong IBM Corporation
4 * Copyright (C) 2004-2005 Stephen Rothwell IBM Corporation
6 * This modules exists as an interface between a Linux secondary partition
7 * running on an iSeries and the primary partition's Virtual Service
8 * Processor (VSP) object. The VSP has final authority over powering on/off
9 * all partitions in the iSeries. It also provides miscellaneous low-level
10 * machine facility type operations.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include <linux/types.h>
29 #include <linux/errno.h>
30 #include <linux/kernel.h>
31 #include <linux/init.h>
32 #include <linux/completion.h>
33 #include <linux/delay.h>
34 #include <linux/dma-mapping.h>
35 #include <linux/bcd.h>
38 #include <asm/uaccess.h>
40 #include <asm/iSeries/vio.h>
41 #include <asm/iSeries/mf.h>
42 #include <asm/iSeries/HvLpConfig.h>
43 #include <asm/iSeries/ItSpCommArea.h>
44 #include <asm/iSeries/ItLpQueue.h>
47 * This is the structure layout for the Machine Facilites LPAR event
57 u64 state; /* GetStateOut */
58 u64 ipl_type; /* GetIplTypeOut, Function02SelectIplTypeIn */
59 u64 ipl_mode; /* GetIplModeOut, Function02SelectIplModeIn */
60 u64 page[4]; /* GetSrcHistoryIn */
61 u64 flag; /* GetAutoIplWhenPrimaryIplsOut,
62 SetAutoIplWhenPrimaryIplsIn,
63 WhiteButtonPowerOffIn,
64 Function08FastPowerOffIn,
65 IsSpcnRackPowerIncompleteOut */
72 } kern; /* SetKernelImageIn, GetKernelImageIn,
73 SetKernelCmdLineIn, GetKernelCmdLineIn */
74 u32 length_out; /* GetKernelImageOut, GetKernelCmdLineOut */
80 struct completion com;
81 struct vsp_cmd_data *response;
95 typedef void (*ce_msg_comp_hdlr)(void *token, struct ce_msg_data *vsp_cmd_rsp);
97 struct ce_msg_comp_data {
98 ce_msg_comp_hdlr handler;
105 struct ce_msg_comp_data *completion;
108 struct io_mf_lp_event {
109 struct HvLpEvent hp_lp_event;
110 u16 subtype_result_code;
114 struct alloc_data alloc;
115 struct ce_msg_data ce_msg;
116 struct vsp_cmd_data vsp_cmd;
120 #define subtype_data(a, b, c, d) \
121 (((a) << 24) + ((b) << 16) + ((c) << 8) + (d))
124 * All outgoing event traffic is kept on a FIFO queue. The first
125 * pointer points to the one that is outstanding, and all new
126 * requests get stuck on the end. Also, we keep a certain number of
127 * preallocated pending events so that we can operate very early in
128 * the boot up sequence (before kmalloc is ready).
130 struct pending_event {
131 struct pending_event *next;
132 struct io_mf_lp_event event;
133 MFCompleteHandler hdlr;
135 unsigned dma_data_length;
136 unsigned remote_address;
138 static spinlock_t pending_event_spinlock;
139 static struct pending_event *pending_event_head;
140 static struct pending_event *pending_event_tail;
141 static struct pending_event *pending_event_avail;
142 static struct pending_event pending_event_prealloc[16];
145 * Put a pending event onto the available queue, so it can get reused.
146 * Attention! You must have the pending_event_spinlock before calling!
148 static void free_pending_event(struct pending_event *ev)
151 ev->next = pending_event_avail;
152 pending_event_avail = ev;
157 * Enqueue the outbound event onto the stack. If the queue was
158 * empty to begin with, we must also issue it via the Hypervisor
159 * interface. There is a section of code below that will touch
160 * the first stack pointer without the protection of the pending_event_spinlock.
161 * This is OK, because we know that nobody else will be modifying
162 * the first pointer when we do this.
164 static int signal_event(struct pending_event *ev)
169 struct pending_event *ev1;
172 /* enqueue the event */
175 spin_lock_irqsave(&pending_event_spinlock, flags);
176 if (pending_event_head == NULL)
177 pending_event_head = ev;
180 pending_event_tail->next = ev;
182 pending_event_tail = ev;
183 spin_unlock_irqrestore(&pending_event_spinlock, flags);
190 /* any DMA data to send beforehand? */
191 if (pending_event_head->dma_data_length > 0)
192 HvCallEvent_dmaToSp(pending_event_head->dma_data,
193 pending_event_head->remote_address,
194 pending_event_head->dma_data_length,
195 HvLpDma_Direction_LocalToRemote);
197 hv_rc = HvCallEvent_signalLpEvent(
198 &pending_event_head->event.hp_lp_event);
199 if (hv_rc != HvLpEvent_Rc_Good) {
200 printk(KERN_ERR "mf.c: HvCallEvent_signalLpEvent() "
201 "failed with %d\n", (int)hv_rc);
203 spin_lock_irqsave(&pending_event_spinlock, flags);
204 ev1 = pending_event_head;
205 pending_event_head = pending_event_head->next;
206 if (pending_event_head != NULL)
208 spin_unlock_irqrestore(&pending_event_spinlock, flags);
212 else if (ev1->hdlr != NULL)
213 (*ev1->hdlr)((void *)ev1->event.hp_lp_event.xCorrelationToken, -EIO);
215 spin_lock_irqsave(&pending_event_spinlock, flags);
216 free_pending_event(ev1);
217 spin_unlock_irqrestore(&pending_event_spinlock, flags);
225 * Allocate a new pending_event structure, and initialize it.
227 static struct pending_event *new_pending_event(void)
229 struct pending_event *ev = NULL;
230 HvLpIndex primary_lp = HvLpConfig_getPrimaryLpIndex();
232 struct HvLpEvent *hev;
234 spin_lock_irqsave(&pending_event_spinlock, flags);
235 if (pending_event_avail != NULL) {
236 ev = pending_event_avail;
237 pending_event_avail = pending_event_avail->next;
239 spin_unlock_irqrestore(&pending_event_spinlock, flags);
241 ev = kmalloc(sizeof(struct pending_event), GFP_ATOMIC);
243 printk(KERN_ERR "mf.c: unable to kmalloc %ld bytes\n",
244 sizeof(struct pending_event));
248 memset(ev, 0, sizeof(struct pending_event));
249 hev = &ev->event.hp_lp_event;
250 hev->xFlags.xValid = 1;
251 hev->xFlags.xAckType = HvLpEvent_AckType_ImmediateAck;
252 hev->xFlags.xAckInd = HvLpEvent_AckInd_DoAck;
253 hev->xFlags.xFunction = HvLpEvent_Function_Int;
254 hev->xType = HvLpEvent_Type_MachineFac;
255 hev->xSourceLp = HvLpConfig_getLpIndex();
256 hev->xTargetLp = primary_lp;
257 hev->xSizeMinus1 = sizeof(ev->event) - 1;
258 hev->xRc = HvLpEvent_Rc_Good;
259 hev->xSourceInstanceId = HvCallEvent_getSourceLpInstanceId(primary_lp,
260 HvLpEvent_Type_MachineFac);
261 hev->xTargetInstanceId = HvCallEvent_getTargetLpInstanceId(primary_lp,
262 HvLpEvent_Type_MachineFac);
267 static int signal_vsp_instruction(struct vsp_cmd_data *vsp_cmd)
269 struct pending_event *ev = new_pending_event();
271 struct vsp_rsp_data response;
276 init_completion(&response.com);
277 response.response = vsp_cmd;
278 ev->event.hp_lp_event.xSubtype = 6;
279 ev->event.hp_lp_event.x.xSubtypeData =
280 subtype_data('M', 'F', 'V', 'I');
281 ev->event.data.vsp_cmd.token = (u64)&response;
282 ev->event.data.vsp_cmd.cmd = vsp_cmd->cmd;
283 ev->event.data.vsp_cmd.lp_index = HvLpConfig_getLpIndex();
284 ev->event.data.vsp_cmd.result_code = 0xFF;
285 ev->event.data.vsp_cmd.reserved = 0;
286 memcpy(&(ev->event.data.vsp_cmd.sub_data),
287 &(vsp_cmd->sub_data), sizeof(vsp_cmd->sub_data));
290 rc = signal_event(ev);
292 wait_for_completion(&response.com);
298 * Send a 12-byte CE message to the primary partition VSP object
300 static int signal_ce_msg(char *ce_msg, struct ce_msg_comp_data *completion)
302 struct pending_event *ev = new_pending_event();
307 ev->event.hp_lp_event.xSubtype = 0;
308 ev->event.hp_lp_event.x.xSubtypeData =
309 subtype_data('M', 'F', 'C', 'E');
310 memcpy(ev->event.data.ce_msg.ce_msg, ce_msg, 12);
311 ev->event.data.ce_msg.completion = completion;
312 return signal_event(ev);
316 * Send a 12-byte CE message (with no data) to the primary partition VSP object
318 static int signal_ce_msg_simple(u8 ce_op, struct ce_msg_comp_data *completion)
322 memset(ce_msg, 0, sizeof(ce_msg));
324 return signal_ce_msg(ce_msg, completion);
328 * Send a 12-byte CE message and DMA data to the primary partition VSP object
330 static int dma_and_signal_ce_msg(char *ce_msg,
331 struct ce_msg_comp_data *completion, void *dma_data,
332 unsigned dma_data_length, unsigned remote_address)
334 struct pending_event *ev = new_pending_event();
339 ev->event.hp_lp_event.xSubtype = 0;
340 ev->event.hp_lp_event.x.xSubtypeData =
341 subtype_data('M', 'F', 'C', 'E');
342 memcpy(ev->event.data.ce_msg.ce_msg, ce_msg, 12);
343 ev->event.data.ce_msg.completion = completion;
344 memcpy(ev->dma_data, dma_data, dma_data_length);
345 ev->dma_data_length = dma_data_length;
346 ev->remote_address = remote_address;
347 return signal_event(ev);
351 * Initiate a nice (hopefully) shutdown of Linux. We simply are
352 * going to try and send the init process a SIGINT signal. If
353 * this fails (why?), we'll simply force it off in a not-so-nice
356 static int shutdown(void)
358 int rc = kill_proc(1, SIGINT, 1);
361 printk(KERN_ALERT "mf.c: SIGINT to init failed (%d), "
362 "hard shutdown commencing\n", rc);
365 printk(KERN_INFO "mf.c: init has been successfully notified "
366 "to proceed with shutdown\n");
371 * The primary partition VSP object is sending us a new
372 * event flow. Handle it...
374 static void handle_int(struct io_mf_lp_event *event)
376 struct ce_msg_data *ce_msg_data;
377 struct ce_msg_data *pce_msg_data;
379 struct pending_event *pev;
381 /* ack the interrupt */
382 event->hp_lp_event.xRc = HvLpEvent_Rc_Good;
383 HvCallEvent_ackLpEvent(&event->hp_lp_event);
385 /* process interrupt */
386 switch (event->hp_lp_event.xSubtype) {
387 case 0: /* CE message */
388 ce_msg_data = &event->data.ce_msg;
389 switch (ce_msg_data->ce_msg[3]) {
390 case 0x5B: /* power control notification */
391 if ((ce_msg_data->ce_msg[5] & 0x20) != 0) {
392 printk(KERN_INFO "mf.c: Commencing partition shutdown\n");
394 signal_ce_msg_simple(0xDB, NULL);
397 case 0xC0: /* get time */
398 spin_lock_irqsave(&pending_event_spinlock, flags);
399 pev = pending_event_head;
401 pending_event_head = pending_event_head->next;
402 spin_unlock_irqrestore(&pending_event_spinlock, flags);
405 pce_msg_data = &pev->event.data.ce_msg;
406 if (pce_msg_data->ce_msg[3] != 0x40)
408 if (pce_msg_data->completion != NULL) {
409 ce_msg_comp_hdlr handler =
410 pce_msg_data->completion->handler;
411 void *token = pce_msg_data->completion->token;
414 (*handler)(token, ce_msg_data);
416 spin_lock_irqsave(&pending_event_spinlock, flags);
417 free_pending_event(pev);
418 spin_unlock_irqrestore(&pending_event_spinlock, flags);
419 /* send next waiting event */
420 if (pending_event_head != NULL)
425 case 1: /* IT sys shutdown */
426 printk(KERN_INFO "mf.c: Commencing system shutdown\n");
433 * The primary partition VSP object is acknowledging the receipt
434 * of a flow we sent to them. If there are other flows queued
435 * up, we must send another one now...
437 static void handle_ack(struct io_mf_lp_event *event)
440 struct pending_event *two = NULL;
441 unsigned long free_it = 0;
442 struct ce_msg_data *ce_msg_data;
443 struct ce_msg_data *pce_msg_data;
444 struct vsp_rsp_data *rsp;
446 /* handle current event */
447 if (pending_event_head == NULL) {
448 printk(KERN_ERR "mf.c: stack empty for receiving ack\n");
452 switch (event->hp_lp_event.xSubtype) {
454 ce_msg_data = &event->data.ce_msg;
455 if (ce_msg_data->ce_msg[3] != 0x40) {
459 if (ce_msg_data->ce_msg[2] == 0)
462 pce_msg_data = &pending_event_head->event.data.ce_msg;
463 if (pce_msg_data->completion != NULL) {
464 ce_msg_comp_hdlr handler =
465 pce_msg_data->completion->handler;
466 void *token = pce_msg_data->completion->token;
469 (*handler)(token, ce_msg_data);
472 case 4: /* allocate */
473 case 5: /* deallocate */
474 if (pending_event_head->hdlr != NULL)
475 (*pending_event_head->hdlr)((void *)event->hp_lp_event.xCorrelationToken, event->data.alloc.count);
480 rsp = (struct vsp_rsp_data *)event->data.vsp_cmd.token;
482 printk(KERN_ERR "mf.c: no rsp\n");
485 if (rsp->response != NULL)
486 memcpy(rsp->response, &event->data.vsp_cmd,
487 sizeof(event->data.vsp_cmd));
492 /* remove from queue */
493 spin_lock_irqsave(&pending_event_spinlock, flags);
494 if ((pending_event_head != NULL) && (free_it == 1)) {
495 struct pending_event *oldHead = pending_event_head;
497 pending_event_head = pending_event_head->next;
498 two = pending_event_head;
499 free_pending_event(oldHead);
501 spin_unlock_irqrestore(&pending_event_spinlock, flags);
503 /* send next waiting event */
509 * This is the generic event handler we are registering with
510 * the Hypervisor. Ensure the flows are for us, and then
511 * parse it enough to know if it is an interrupt or an
514 static void hv_handler(struct HvLpEvent *event, struct pt_regs *regs)
516 if ((event != NULL) && (event->xType == HvLpEvent_Type_MachineFac)) {
517 switch(event->xFlags.xFunction) {
518 case HvLpEvent_Function_Ack:
519 handle_ack((struct io_mf_lp_event *)event);
521 case HvLpEvent_Function_Int:
522 handle_int((struct io_mf_lp_event *)event);
525 printk(KERN_ERR "mf.c: non ack/int event received\n");
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.
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 void mf_display_progress(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 void mf_clear_src(void)
660 signal_ce_msg_simple(0x4b, NULL);
664 * Initialization code here.
671 spin_lock_init(&pending_event_spinlock);
673 i < sizeof(pending_event_prealloc) / sizeof(*pending_event_prealloc);
675 free_pending_event(&pending_event_prealloc[i]);
676 HvLpEvent_registerHandler(HvLpEvent_Type_MachineFac, &hv_handler);
678 /* virtual continue ack */
679 signal_ce_msg_simple(0x57, NULL);
681 /* initialization complete */
682 printk(KERN_NOTICE "mf.c: iSeries Linux LPAR Machine Facilities "
686 struct rtc_time_data {
687 struct completion com;
688 struct ce_msg_data ce_msg;
692 static void get_rtc_time_complete(void *token, struct ce_msg_data *ce_msg)
694 struct rtc_time_data *rtc = token;
696 memcpy(&rtc->ce_msg, ce_msg, sizeof(rtc->ce_msg));
701 static int rtc_set_tm(int rc, u8 *ce_msg, struct rtc_time *tm)
716 if ((ce_msg[2] == 0xa9) ||
717 (ce_msg[2] == 0xaf)) {
718 /* TOD clock is not set */
756 int mf_get_rtc(struct rtc_time *tm)
758 struct ce_msg_comp_data ce_complete;
759 struct rtc_time_data rtc_data;
762 memset(&ce_complete, 0, sizeof(ce_complete));
763 memset(&rtc_data, 0, sizeof(rtc_data));
764 init_completion(&rtc_data.com);
765 ce_complete.handler = &get_rtc_time_complete;
766 ce_complete.token = &rtc_data;
767 rc = signal_ce_msg_simple(0x40, &ce_complete);
770 wait_for_completion(&rtc_data.com);
771 return rtc_set_tm(rtc_data.rc, rtc_data.ce_msg.ce_msg, tm);
774 struct boot_rtc_time_data {
776 struct ce_msg_data ce_msg;
780 static void get_boot_rtc_time_complete(void *token, struct ce_msg_data *ce_msg)
782 struct boot_rtc_time_data *rtc = token;
784 memcpy(&rtc->ce_msg, ce_msg, sizeof(rtc->ce_msg));
789 int mf_get_boot_rtc(struct rtc_time *tm)
791 struct ce_msg_comp_data ce_complete;
792 struct boot_rtc_time_data rtc_data;
795 memset(&ce_complete, 0, sizeof(ce_complete));
796 memset(&rtc_data, 0, sizeof(rtc_data));
798 ce_complete.handler = &get_boot_rtc_time_complete;
799 ce_complete.token = &rtc_data;
800 rc = signal_ce_msg_simple(0x40, &ce_complete);
803 /* We need to poll here as we are not yet taking interrupts */
804 while (rtc_data.busy) {
805 extern unsigned long lpevent_count;
806 struct ItLpQueue *lpq = get_paca()->lpqueue_ptr;
807 if (lpq && ItLpQueue_isLpIntPending(lpq))
808 lpevent_count += ItLpQueue_process(lpq, NULL);
810 return rtc_set_tm(rtc_data.rc, rtc_data.ce_msg.ce_msg, tm);
813 int mf_set_rtc(struct rtc_time *tm)
816 u8 day, mon, hour, min, sec, y1, y2;
819 year = 1900 + tm->tm_year;
827 mon = tm->tm_mon + 1;
837 memset(ce_time, 0, sizeof(ce_time));
847 return signal_ce_msg(ce_time, NULL);
850 #ifdef CONFIG_PROC_FS
852 static int proc_mf_dump_cmdline(char *page, char **start, off_t off,
853 int count, int *eof, void *data)
857 struct vsp_cmd_data vsp_cmd;
861 /* The HV appears to return no more than 256 bytes of command line */
864 if ((off + count) > 256)
867 dma_addr = dma_map_single(iSeries_vio_dev, page, off + count,
869 if (dma_mapping_error(dma_addr))
871 memset(page, 0, off + count);
872 memset(&vsp_cmd, 0, sizeof(vsp_cmd));
874 vsp_cmd.sub_data.kern.token = dma_addr;
875 vsp_cmd.sub_data.kern.address_type = HvLpDma_AddressType_TceIndex;
876 vsp_cmd.sub_data.kern.side = (u64)data;
877 vsp_cmd.sub_data.kern.length = off + count;
879 rc = signal_vsp_instruction(&vsp_cmd);
880 dma_unmap_single(iSeries_vio_dev, dma_addr, off + count,
884 if (vsp_cmd.result_code != 0)
888 while (len < (off + count)) {
889 if ((*p == '\0') || (*p == '\n')) {
909 static int mf_getVmlinuxChunk(char *buffer, int *size, int offset, u64 side)
911 struct vsp_cmd_data vsp_cmd;
916 dma_addr = dma_map_single(iSeries_vio_dev, buffer, len,
918 memset(buffer, 0, len);
919 memset(&vsp_cmd, 0, sizeof(vsp_cmd));
921 vsp_cmd.sub_data.kern.token = dma_addr;
922 vsp_cmd.sub_data.kern.address_type = HvLpDma_AddressType_TceIndex;
923 vsp_cmd.sub_data.kern.side = side;
924 vsp_cmd.sub_data.kern.offset = offset;
925 vsp_cmd.sub_data.kern.length = len;
927 rc = signal_vsp_instruction(&vsp_cmd);
929 if (vsp_cmd.result_code == 0)
930 *size = vsp_cmd.sub_data.length_out;
935 dma_unmap_single(iSeries_vio_dev, dma_addr, len, DMA_FROM_DEVICE);
940 static int proc_mf_dump_vmlinux(char *page, char **start, off_t off,
941 int count, int *eof, void *data)
943 int sizeToGet = count;
945 if (!capable(CAP_SYS_ADMIN))
948 if (mf_getVmlinuxChunk(page, &sizeToGet, off, (u64)data) == 0) {
949 if (sizeToGet != 0) {
961 static int proc_mf_dump_side(char *page, char **start, off_t off,
962 int count, int *eof, void *data)
965 char mf_current_side = ' ';
966 struct vsp_cmd_data vsp_cmd;
968 memset(&vsp_cmd, 0, sizeof(vsp_cmd));
970 vsp_cmd.sub_data.ipl_type = 0;
973 if (signal_vsp_instruction(&vsp_cmd) == 0) {
974 if (vsp_cmd.result_code == 0) {
975 switch (vsp_cmd.sub_data.ipl_type) {
976 case 0: mf_current_side = 'A';
978 case 1: mf_current_side = 'B';
980 case 2: mf_current_side = 'C';
982 default: mf_current_side = 'D';
988 len = sprintf(page, "%c\n", mf_current_side);
990 if (len <= (off + count))
1001 static int proc_mf_change_side(struct file *file, const char __user *buffer,
1002 unsigned long count, void *data)
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);
1041 static void mf_getSrcHistory(char *buffer, int size)
1043 struct IplTypeReturnStuff return_stuff;
1044 struct pending_event *ev = new_pending_event();
1048 pages[0] = kmalloc(4096, GFP_ATOMIC);
1049 pages[1] = kmalloc(4096, GFP_ATOMIC);
1050 pages[2] = kmalloc(4096, GFP_ATOMIC);
1051 pages[3] = kmalloc(4096, GFP_ATOMIC);
1052 if ((ev == NULL) || (pages[0] == NULL) || (pages[1] == NULL)
1053 || (pages[2] == NULL) || (pages[3] == NULL))
1056 return_stuff.xType = 0;
1057 return_stuff.xRc = 0;
1058 return_stuff.xDone = 0;
1059 ev->event.hp_lp_event.xSubtype = 6;
1060 ev->event.hp_lp_event.x.xSubtypeData =
1061 subtype_data('M', 'F', 'V', 'I');
1062 ev->event.data.vsp_cmd.xEvent = &return_stuff;
1063 ev->event.data.vsp_cmd.cmd = 4;
1064 ev->event.data.vsp_cmd.lp_index = HvLpConfig_getLpIndex();
1065 ev->event.data.vsp_cmd.result_code = 0xFF;
1066 ev->event.data.vsp_cmd.reserved = 0;
1067 ev->event.data.vsp_cmd.sub_data.page[0] = ISERIES_HV_ADDR(pages[0]);
1068 ev->event.data.vsp_cmd.sub_data.page[1] = ISERIES_HV_ADDR(pages[1]);
1069 ev->event.data.vsp_cmd.sub_data.page[2] = ISERIES_HV_ADDR(pages[2]);
1070 ev->event.data.vsp_cmd.sub_data.page[3] = ISERIES_HV_ADDR(pages[3]);
1072 if (signal_event(ev) != 0)
1075 while (return_stuff.xDone != 1)
1077 if (return_stuff.xRc == 0)
1078 memcpy(buffer, pages[0], size);
1086 static int proc_mf_dump_src(char *page, char **start, off_t off,
1087 int count, int *eof, void *data)
1092 mf_getSrcHistory(page, count);
1101 *start = page + off;
1108 static int proc_mf_change_src(struct file *file, const char __user *buffer,
1109 unsigned long count, void *data)
1113 if (!capable(CAP_SYS_ADMIN))
1116 if ((count < 4) && (count != 1)) {
1117 printk(KERN_ERR "mf_proc: invalid src\n");
1121 if (count > (sizeof(stkbuf) - 1))
1122 count = sizeof(stkbuf) - 1;
1123 if (copy_from_user(stkbuf, buffer, count))
1126 if ((count == 1) && (*stkbuf == '\0'))
1129 mf_display_src(*(u32 *)stkbuf);
1134 static int proc_mf_change_cmdline(struct file *file, const char __user *buffer,
1135 unsigned long count, void *data)
1137 struct vsp_cmd_data vsp_cmd;
1138 dma_addr_t dma_addr;
1142 if (!capable(CAP_SYS_ADMIN))
1146 page = dma_alloc_coherent(iSeries_vio_dev, count, &dma_addr,
1153 if (copy_from_user(page, buffer, count))
1156 memset(&vsp_cmd, 0, sizeof(vsp_cmd));
1158 vsp_cmd.sub_data.kern.token = dma_addr;
1159 vsp_cmd.sub_data.kern.address_type = HvLpDma_AddressType_TceIndex;
1160 vsp_cmd.sub_data.kern.side = (u64)data;
1161 vsp_cmd.sub_data.kern.length = count;
1163 (void)signal_vsp_instruction(&vsp_cmd);
1167 dma_free_coherent(iSeries_vio_dev, count, page, dma_addr);
1172 static ssize_t proc_mf_change_vmlinux(struct file *file,
1173 const char __user *buf,
1174 size_t count, loff_t *ppos)
1176 struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode);
1178 dma_addr_t dma_addr;
1180 struct vsp_cmd_data vsp_cmd;
1183 if (!capable(CAP_SYS_ADMIN))
1187 page = dma_alloc_coherent(iSeries_vio_dev, count, &dma_addr,
1191 printk(KERN_ERR "mf.c: couldn't allocate memory to set vmlinux chunk\n");
1195 if (copy_from_user(page, buf, count))
1198 memset(&vsp_cmd, 0, sizeof(vsp_cmd));
1200 vsp_cmd.sub_data.kern.token = dma_addr;
1201 vsp_cmd.sub_data.kern.address_type = HvLpDma_AddressType_TceIndex;
1202 vsp_cmd.sub_data.kern.side = (u64)dp->data;
1203 vsp_cmd.sub_data.kern.offset = *ppos;
1204 vsp_cmd.sub_data.kern.length = count;
1206 rc = signal_vsp_instruction(&vsp_cmd);
1210 if (vsp_cmd.result_code != 0)
1216 dma_free_coherent(iSeries_vio_dev, count, page, dma_addr);
1221 static struct file_operations proc_vmlinux_operations = {
1222 .write = proc_mf_change_vmlinux,
1225 static int __init mf_proc_init(void)
1227 struct proc_dir_entry *mf_proc_root;
1228 struct proc_dir_entry *ent;
1229 struct proc_dir_entry *mf;
1233 mf_proc_root = proc_mkdir("iSeries/mf", NULL);
1238 for (i = 0; i < 4; i++) {
1240 mf = proc_mkdir(name, mf_proc_root);
1244 ent = create_proc_entry("cmdline", S_IFREG|S_IRUSR|S_IWUSR, mf);
1248 ent->data = (void *)(long)i;
1249 ent->read_proc = proc_mf_dump_cmdline;
1250 ent->write_proc = proc_mf_change_cmdline;
1252 if (i == 3) /* no vmlinux entry for 'D' */
1255 ent = create_proc_entry("vmlinux", S_IFREG|S_IWUSR, mf);
1259 ent->data = (void *)(long)i;
1260 ent->proc_fops = &proc_vmlinux_operations;
1263 ent = create_proc_entry("side", S_IFREG|S_IRUSR|S_IWUSR, mf_proc_root);
1267 ent->data = (void *)0;
1268 ent->read_proc = proc_mf_dump_side;
1269 ent->write_proc = proc_mf_change_side;
1271 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 */