blob: 18054e922bd17e2d5430f54b530556fc4c537e34 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Stephen Rothwellc8b84972005-09-27 18:44:42 +10002 * Copyright (C) 2001 Troy D. Armstrong IBM Corporation
3 * Copyright (C) 2004-2005 Stephen Rothwell IBM Corporation
4 *
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.
10 *
11 *
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.
16 *
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.
21 *
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
25 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
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>
Paul Mackerras143a1de2005-10-19 23:11:21 +100035#include <linux/rtc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37#include <asm/time.h>
38#include <asm/uaccess.h>
Stephen Rothwelld0e8e292005-05-25 16:29:26 +100039#include <asm/paca.h>
Stephen Rothwell426c1a12005-10-14 14:51:42 +100040#include <asm/abs_addr.h>
Kelly Dalyb4206772005-11-02 15:13:57 +110041#include <asm/iseries/vio.h>
Kelly Dalybbc8b622005-11-02 15:10:38 +110042#include <asm/iseries/mf.h>
Kelly Daly15b17182005-11-02 11:55:28 +110043#include <asm/iseries/hv_lp_config.h>
Kelly Daly8875ccf2005-11-02 14:13:34 +110044#include <asm/iseries/it_lp_queue.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Stephen Rothwellc8b84972005-09-27 18:44:42 +100046#include "setup.h"
47
48extern int piranha_simulator;
Michael Ellerman260de222006-03-21 20:46:02 +110049static int mf_initialized;
Stephen Rothwellc8b84972005-09-27 18:44:42 +100050
Linus Torvalds1da177e2005-04-16 15:20:36 -070051/*
52 * This is the structure layout for the Machine Facilites LPAR event
53 * flows.
54 */
55struct vsp_cmd_data {
56 u64 token;
57 u16 cmd;
58 HvLpIndex lp_index;
59 u8 result_code;
60 u32 reserved;
61 union {
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 */
71 struct {
72 u64 token;
73 u64 address_type;
74 u64 side;
75 u32 length;
76 u32 offset;
77 } kern; /* SetKernelImageIn, GetKernelImageIn,
78 SetKernelCmdLineIn, GetKernelCmdLineIn */
79 u32 length_out; /* GetKernelImageOut, GetKernelCmdLineOut */
80 u8 reserved[80];
81 } sub_data;
82};
83
84struct vsp_rsp_data {
85 struct completion com;
86 struct vsp_cmd_data *response;
87};
88
89struct alloc_data {
90 u16 size;
91 u16 type;
92 u32 count;
93 u16 reserved1;
94 u8 reserved2;
95 HvLpIndex target_lp;
96};
97
98struct ce_msg_data;
99
100typedef void (*ce_msg_comp_hdlr)(void *token, struct ce_msg_data *vsp_cmd_rsp);
101
102struct ce_msg_comp_data {
103 ce_msg_comp_hdlr handler;
104 void *token;
105};
106
107struct ce_msg_data {
108 u8 ce_msg[12];
109 char reserved[4];
110 struct ce_msg_comp_data *completion;
111};
112
113struct io_mf_lp_event {
114 struct HvLpEvent hp_lp_event;
115 u16 subtype_result_code;
116 u16 reserved1;
117 u32 reserved2;
118 union {
119 struct alloc_data alloc;
120 struct ce_msg_data ce_msg;
121 struct vsp_cmd_data vsp_cmd;
122 } data;
123};
124
125#define subtype_data(a, b, c, d) \
126 (((a) << 24) + ((b) << 16) + ((c) << 8) + (d))
127
128/*
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).
134 */
135struct pending_event {
136 struct pending_event *next;
137 struct io_mf_lp_event event;
138 MFCompleteHandler hdlr;
139 char dma_data[72];
140 unsigned dma_data_length;
141 unsigned remote_address;
142};
143static spinlock_t pending_event_spinlock;
144static struct pending_event *pending_event_head;
145static struct pending_event *pending_event_tail;
146static struct pending_event *pending_event_avail;
Michael Ellerman260de222006-03-21 20:46:02 +1100147#define PENDING_EVENT_PREALLOC_LEN 16
148static struct pending_event pending_event_prealloc[PENDING_EVENT_PREALLOC_LEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
150/*
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!
153 */
154static void free_pending_event(struct pending_event *ev)
155{
156 if (ev != NULL) {
157 ev->next = pending_event_avail;
158 pending_event_avail = ev;
159 }
160}
161
162/*
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.
169 */
170static int signal_event(struct pending_event *ev)
171{
172 int rc = 0;
173 unsigned long flags;
174 int go = 1;
175 struct pending_event *ev1;
176 HvLpEvent_Rc hv_rc;
177
178 /* enqueue the event */
179 if (ev != NULL) {
180 ev->next = NULL;
181 spin_lock_irqsave(&pending_event_spinlock, flags);
182 if (pending_event_head == NULL)
183 pending_event_head = ev;
184 else {
185 go = 0;
186 pending_event_tail->next = ev;
187 }
188 pending_event_tail = ev;
189 spin_unlock_irqrestore(&pending_event_spinlock, flags);
190 }
191
192 /* send the event */
193 while (go) {
194 go = 0;
195
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);
202
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);
208
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)
213 go = 1;
214 spin_unlock_irqrestore(&pending_event_spinlock, flags);
215
216 if (ev1 == ev)
217 rc = -EIO;
218 else if (ev1->hdlr != NULL)
219 (*ev1->hdlr)((void *)ev1->event.hp_lp_event.xCorrelationToken, -EIO);
220
221 spin_lock_irqsave(&pending_event_spinlock, flags);
222 free_pending_event(ev1);
223 spin_unlock_irqrestore(&pending_event_spinlock, flags);
224 }
225 }
226
227 return rc;
228}
229
230/*
231 * Allocate a new pending_event structure, and initialize it.
232 */
233static struct pending_event *new_pending_event(void)
234{
235 struct pending_event *ev = NULL;
236 HvLpIndex primary_lp = HvLpConfig_getPrimaryLpIndex();
237 unsigned long flags;
238 struct HvLpEvent *hev;
239
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;
244 }
245 spin_unlock_irqrestore(&pending_event_spinlock, flags);
246 if (ev == NULL) {
247 ev = kmalloc(sizeof(struct pending_event), GFP_ATOMIC);
248 if (ev == NULL) {
249 printk(KERN_ERR "mf.c: unable to kmalloc %ld bytes\n",
250 sizeof(struct pending_event));
251 return NULL;
252 }
253 }
254 memset(ev, 0, sizeof(struct pending_event));
255 hev = &ev->event.hp_lp_event;
Stephen Rothwell677f8c02006-01-12 13:47:43 +1100256 hev->flags = HV_LP_EVENT_VALID | HV_LP_EVENT_DO_ACK | HV_LP_EVENT_INT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 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);
266
267 return ev;
268}
269
270static int signal_vsp_instruction(struct vsp_cmd_data *vsp_cmd)
271{
272 struct pending_event *ev = new_pending_event();
273 int rc;
274 struct vsp_rsp_data response;
275
276 if (ev == NULL)
277 return -ENOMEM;
278
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));
291 mb();
292
293 rc = signal_event(ev);
294 if (rc == 0)
295 wait_for_completion(&response.com);
296 return rc;
297}
298
299
300/*
301 * Send a 12-byte CE message to the primary partition VSP object
302 */
303static int signal_ce_msg(char *ce_msg, struct ce_msg_comp_data *completion)
304{
305 struct pending_event *ev = new_pending_event();
306
307 if (ev == NULL)
308 return -ENOMEM;
309
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);
316}
317
318/*
319 * Send a 12-byte CE message (with no data) to the primary partition VSP object
320 */
321static int signal_ce_msg_simple(u8 ce_op, struct ce_msg_comp_data *completion)
322{
323 u8 ce_msg[12];
324
325 memset(ce_msg, 0, sizeof(ce_msg));
326 ce_msg[3] = ce_op;
327 return signal_ce_msg(ce_msg, completion);
328}
329
330/*
331 * Send a 12-byte CE message and DMA data to the primary partition VSP object
332 */
333static 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)
336{
337 struct pending_event *ev = new_pending_event();
338
339 if (ev == NULL)
340 return -ENOMEM;
341
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);
351}
352
353/*
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
357 * manner.
358 */
359static int shutdown(void)
360{
361 int rc = kill_proc(1, SIGINT, 1);
362
363 if (rc) {
364 printk(KERN_ALERT "mf.c: SIGINT to init failed (%d), "
365 "hard shutdown commencing\n", rc);
366 mf_power_off();
367 } else
368 printk(KERN_INFO "mf.c: init has been successfully notified "
369 "to proceed with shutdown\n");
370 return rc;
371}
372
373/*
374 * The primary partition VSP object is sending us a new
375 * event flow. Handle it...
376 */
377static void handle_int(struct io_mf_lp_event *event)
378{
379 struct ce_msg_data *ce_msg_data;
380 struct ce_msg_data *pce_msg_data;
381 unsigned long flags;
382 struct pending_event *pev;
383
384 /* ack the interrupt */
385 event->hp_lp_event.xRc = HvLpEvent_Rc_Good;
386 HvCallEvent_ackLpEvent(&event->hp_lp_event);
387
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");
396 if (shutdown() == 0)
397 signal_ce_msg_simple(0xDB, NULL);
398 }
399 break;
400 case 0xC0: /* get time */
401 spin_lock_irqsave(&pending_event_spinlock, flags);
402 pev = pending_event_head;
403 if (pev != NULL)
404 pending_event_head = pending_event_head->next;
405 spin_unlock_irqrestore(&pending_event_spinlock, flags);
406 if (pev == NULL)
407 break;
408 pce_msg_data = &pev->event.data.ce_msg;
409 if (pce_msg_data->ce_msg[3] != 0x40)
410 break;
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;
415
416 if (handler != NULL)
417 (*handler)(token, ce_msg_data);
418 }
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)
424 signal_event(NULL);
425 break;
426 }
427 break;
428 case 1: /* IT sys shutdown */
429 printk(KERN_INFO "mf.c: Commencing system shutdown\n");
430 shutdown();
431 break;
432 }
433}
434
435/*
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...
439 */
440static void handle_ack(struct io_mf_lp_event *event)
441{
442 unsigned long flags;
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;
448
449 /* handle current event */
450 if (pending_event_head == NULL) {
451 printk(KERN_ERR "mf.c: stack empty for receiving ack\n");
452 return;
453 }
454
455 switch (event->hp_lp_event.xSubtype) {
456 case 0: /* CE msg */
457 ce_msg_data = &event->data.ce_msg;
458 if (ce_msg_data->ce_msg[3] != 0x40) {
459 free_it = 1;
460 break;
461 }
462 if (ce_msg_data->ce_msg[2] == 0)
463 break;
464 free_it = 1;
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;
470
471 if (handler != NULL)
472 (*handler)(token, ce_msg_data);
473 }
474 break;
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);
479 free_it = 1;
480 break;
481 case 6:
482 free_it = 1;
483 rsp = (struct vsp_rsp_data *)event->data.vsp_cmd.token;
484 if (rsp == NULL) {
485 printk(KERN_ERR "mf.c: no rsp\n");
486 break;
487 }
488 if (rsp->response != NULL)
489 memcpy(rsp->response, &event->data.vsp_cmd,
490 sizeof(event->data.vsp_cmd));
491 complete(&rsp->com);
492 break;
493 }
494
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;
499
500 pending_event_head = pending_event_head->next;
501 two = pending_event_head;
502 free_pending_event(oldHead);
503 }
504 spin_unlock_irqrestore(&pending_event_spinlock, flags);
505
506 /* send next waiting event */
507 if (two != NULL)
508 signal_event(NULL);
509}
510
511/*
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
515 * acknowledge.
516 */
517static void hv_handler(struct HvLpEvent *event, struct pt_regs *regs)
518{
519 if ((event != NULL) && (event->xType == HvLpEvent_Type_MachineFac)) {
Stephen Rothwell677f8c02006-01-12 13:47:43 +1100520 if (hvlpevent_is_ack(event))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 handle_ack((struct io_mf_lp_event *)event);
Stephen Rothwell677f8c02006-01-12 13:47:43 +1100522 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 handle_int((struct io_mf_lp_event *)event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 } else
525 printk(KERN_ERR "mf.c: alien event received\n");
526}
527
528/*
529 * Global kernel interface to allocate and seed events into the
530 * Hypervisor.
531 */
532void mf_allocate_lp_events(HvLpIndex target_lp, HvLpEvent_Type type,
533 unsigned size, unsigned count, MFCompleteHandler hdlr,
534 void *user_token)
535{
536 struct pending_event *ev = new_pending_event();
537 int rc;
538
539 if (ev == NULL) {
540 rc = -ENOMEM;
541 } else {
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;
550 ev->hdlr = hdlr;
551 rc = signal_event(ev);
552 }
553 if ((rc != 0) && (hdlr != NULL))
554 (*hdlr)(user_token, rc);
555}
556EXPORT_SYMBOL(mf_allocate_lp_events);
557
558/*
559 * Global kernel interface to unseed and deallocate events already in
560 * Hypervisor.
561 */
562void mf_deallocate_lp_events(HvLpIndex target_lp, HvLpEvent_Type type,
563 unsigned count, MFCompleteHandler hdlr, void *user_token)
564{
565 struct pending_event *ev = new_pending_event();
566 int rc;
567
568 if (ev == NULL)
569 rc = -ENOMEM;
570 else {
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;
578 ev->hdlr = hdlr;
579 rc = signal_event(ev);
580 }
581 if ((rc != 0) && (hdlr != NULL))
582 (*hdlr)(user_token, rc);
583}
584EXPORT_SYMBOL(mf_deallocate_lp_events);
585
586/*
587 * Global kernel interface to tell the VSP object in the primary
588 * partition to power this partition off.
589 */
590void mf_power_off(void)
591{
592 printk(KERN_INFO "mf.c: Down it goes...\n");
593 signal_ce_msg_simple(0x4d, NULL);
594 for (;;)
595 ;
596}
597
598/*
599 * Global kernel interface to tell the VSP object in the primary
600 * partition to reboot this partition.
601 */
Michael Ellermana9ea2102006-03-21 20:46:04 +1100602void mf_reboot(char *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603{
604 printk(KERN_INFO "mf.c: Preparing to bounce...\n");
605 signal_ce_msg_simple(0x4e, NULL);
606 for (;;)
607 ;
608}
609
610/*
611 * Display a single word SRC onto the VSP control panel.
612 */
613void mf_display_src(u32 word)
614{
615 u8 ce[12];
616
617 memset(ce, 0, sizeof(ce));
618 ce[3] = 0x4a;
619 ce[7] = 0x01;
620 ce[8] = word >> 24;
621 ce[9] = word >> 16;
622 ce[10] = word >> 8;
623 ce[11] = word;
624 signal_ce_msg(ce, NULL);
625}
626
627/*
628 * Display a single word SRC of the form "PROGXXXX" on the VSP control panel.
629 */
Michael Ellerman260de222006-03-21 20:46:02 +1100630static __init void mf_display_progress_src(u16 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631{
632 u8 ce[12];
633 u8 src[72];
634
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 ",
640 72);
641 src[6] = value >> 8;
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);
648}
649
650/*
651 * Clear the VSP control panel. Used to "erase" an SRC that was
652 * previously displayed.
653 */
Michael Ellerman260de222006-03-21 20:46:02 +1100654static void mf_clear_src(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655{
656 signal_ce_msg_simple(0x4b, NULL);
657}
658
Michael Ellerman260de222006-03-21 20:46:02 +1100659void __init mf_display_progress(u16 value)
660{
661 if (piranha_simulator || !mf_initialized)
662 return;
663
664 if (0xFFFF == value)
665 mf_clear_src();
666 else
667 mf_display_progress_src(value);
668}
669
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670/*
671 * Initialization code here.
672 */
Michael Ellerman260de222006-03-21 20:46:02 +1100673void __init mf_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674{
675 int i;
676
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 spin_lock_init(&pending_event_spinlock);
Michael Ellerman260de222006-03-21 20:46:02 +1100678
679 for (i = 0; i < PENDING_EVENT_PREALLOC_LEN; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 free_pending_event(&pending_event_prealloc[i]);
Michael Ellerman260de222006-03-21 20:46:02 +1100681
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 HvLpEvent_registerHandler(HvLpEvent_Type_MachineFac, &hv_handler);
683
684 /* virtual continue ack */
685 signal_ce_msg_simple(0x57, NULL);
686
Michael Ellerman260de222006-03-21 20:46:02 +1100687 mf_initialized = 1;
688 mb();
689
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 printk(KERN_NOTICE "mf.c: iSeries Linux LPAR Machine Facilities "
691 "initialized\n");
692}
693
694struct rtc_time_data {
695 struct completion com;
696 struct ce_msg_data ce_msg;
697 int rc;
698};
699
700static void get_rtc_time_complete(void *token, struct ce_msg_data *ce_msg)
701{
702 struct rtc_time_data *rtc = token;
703
704 memcpy(&rtc->ce_msg, ce_msg, sizeof(rtc->ce_msg));
705 rtc->rc = 0;
706 complete(&rtc->com);
707}
708
Stephen Rothwelld0e8e292005-05-25 16:29:26 +1000709static int rtc_set_tm(int rc, u8 *ce_msg, struct rtc_time *tm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 tm->tm_wday = 0;
712 tm->tm_yday = 0;
713 tm->tm_isdst = 0;
Stephen Rothwelld0e8e292005-05-25 16:29:26 +1000714 if (rc) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 tm->tm_sec = 0;
716 tm->tm_min = 0;
717 tm->tm_hour = 0;
718 tm->tm_mday = 15;
719 tm->tm_mon = 5;
720 tm->tm_year = 52;
Stephen Rothwelld0e8e292005-05-25 16:29:26 +1000721 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 }
723
Stephen Rothwelld0e8e292005-05-25 16:29:26 +1000724 if ((ce_msg[2] == 0xa9) ||
725 (ce_msg[2] == 0xaf)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 /* TOD clock is not set */
727 tm->tm_sec = 1;
728 tm->tm_min = 1;
729 tm->tm_hour = 1;
730 tm->tm_mday = 10;
731 tm->tm_mon = 8;
732 tm->tm_year = 71;
733 mf_set_rtc(tm);
734 }
735 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 u8 year = ce_msg[5];
737 u8 sec = ce_msg[6];
738 u8 min = ce_msg[7];
739 u8 hour = ce_msg[8];
740 u8 day = ce_msg[10];
741 u8 mon = ce_msg[11];
742
743 BCD_TO_BIN(sec);
744 BCD_TO_BIN(min);
745 BCD_TO_BIN(hour);
746 BCD_TO_BIN(day);
747 BCD_TO_BIN(mon);
748 BCD_TO_BIN(year);
749
750 if (year <= 69)
751 year += 100;
752
753 tm->tm_sec = sec;
754 tm->tm_min = min;
755 tm->tm_hour = hour;
756 tm->tm_mday = day;
757 tm->tm_mon = mon;
758 tm->tm_year = year;
759 }
760
761 return 0;
762}
763
Stephen Rothwelld0e8e292005-05-25 16:29:26 +1000764int mf_get_rtc(struct rtc_time *tm)
765{
766 struct ce_msg_comp_data ce_complete;
767 struct rtc_time_data rtc_data;
768 int rc;
769
770 memset(&ce_complete, 0, sizeof(ce_complete));
771 memset(&rtc_data, 0, sizeof(rtc_data));
772 init_completion(&rtc_data.com);
773 ce_complete.handler = &get_rtc_time_complete;
774 ce_complete.token = &rtc_data;
775 rc = signal_ce_msg_simple(0x40, &ce_complete);
776 if (rc)
777 return rc;
778 wait_for_completion(&rtc_data.com);
779 return rtc_set_tm(rtc_data.rc, rtc_data.ce_msg.ce_msg, tm);
780}
781
782struct boot_rtc_time_data {
783 int busy;
784 struct ce_msg_data ce_msg;
785 int rc;
786};
787
788static void get_boot_rtc_time_complete(void *token, struct ce_msg_data *ce_msg)
789{
790 struct boot_rtc_time_data *rtc = token;
791
792 memcpy(&rtc->ce_msg, ce_msg, sizeof(rtc->ce_msg));
793 rtc->rc = 0;
794 rtc->busy = 0;
795}
796
797int mf_get_boot_rtc(struct rtc_time *tm)
798{
799 struct ce_msg_comp_data ce_complete;
800 struct boot_rtc_time_data rtc_data;
801 int rc;
802
803 memset(&ce_complete, 0, sizeof(ce_complete));
804 memset(&rtc_data, 0, sizeof(rtc_data));
805 rtc_data.busy = 1;
806 ce_complete.handler = &get_boot_rtc_time_complete;
807 ce_complete.token = &rtc_data;
808 rc = signal_ce_msg_simple(0x40, &ce_complete);
809 if (rc)
810 return rc;
811 /* We need to poll here as we are not yet taking interrupts */
812 while (rtc_data.busy) {
Michael Ellerman937b31b2005-06-30 15:15:42 +1000813 if (hvlpevent_is_pending())
Michael Ellerman74889802005-06-30 15:15:53 +1000814 process_hvlpevents(NULL);
Stephen Rothwelld0e8e292005-05-25 16:29:26 +1000815 }
816 return rtc_set_tm(rtc_data.rc, rtc_data.ce_msg.ce_msg, tm);
817}
818
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819int mf_set_rtc(struct rtc_time *tm)
820{
821 char ce_time[12];
822 u8 day, mon, hour, min, sec, y1, y2;
823 unsigned year;
824
825 year = 1900 + tm->tm_year;
826 y1 = year / 100;
827 y2 = year % 100;
828
829 sec = tm->tm_sec;
830 min = tm->tm_min;
831 hour = tm->tm_hour;
832 day = tm->tm_mday;
833 mon = tm->tm_mon + 1;
834
835 BIN_TO_BCD(sec);
836 BIN_TO_BCD(min);
837 BIN_TO_BCD(hour);
838 BIN_TO_BCD(mon);
839 BIN_TO_BCD(day);
840 BIN_TO_BCD(y1);
841 BIN_TO_BCD(y2);
842
843 memset(ce_time, 0, sizeof(ce_time));
844 ce_time[3] = 0x41;
845 ce_time[4] = y1;
846 ce_time[5] = y2;
847 ce_time[6] = sec;
848 ce_time[7] = min;
849 ce_time[8] = hour;
850 ce_time[10] = day;
851 ce_time[11] = mon;
852
853 return signal_ce_msg(ce_time, NULL);
854}
855
856#ifdef CONFIG_PROC_FS
857
858static int proc_mf_dump_cmdline(char *page, char **start, off_t off,
859 int count, int *eof, void *data)
860{
861 int len;
862 char *p;
863 struct vsp_cmd_data vsp_cmd;
864 int rc;
865 dma_addr_t dma_addr;
866
867 /* The HV appears to return no more than 256 bytes of command line */
868 if (off >= 256)
869 return 0;
870 if ((off + count) > 256)
871 count = 256 - off;
872
873 dma_addr = dma_map_single(iSeries_vio_dev, page, off + count,
874 DMA_FROM_DEVICE);
875 if (dma_mapping_error(dma_addr))
876 return -ENOMEM;
877 memset(page, 0, off + count);
878 memset(&vsp_cmd, 0, sizeof(vsp_cmd));
879 vsp_cmd.cmd = 33;
880 vsp_cmd.sub_data.kern.token = dma_addr;
881 vsp_cmd.sub_data.kern.address_type = HvLpDma_AddressType_TceIndex;
882 vsp_cmd.sub_data.kern.side = (u64)data;
883 vsp_cmd.sub_data.kern.length = off + count;
884 mb();
885 rc = signal_vsp_instruction(&vsp_cmd);
886 dma_unmap_single(iSeries_vio_dev, dma_addr, off + count,
887 DMA_FROM_DEVICE);
888 if (rc)
889 return rc;
890 if (vsp_cmd.result_code != 0)
891 return -ENOMEM;
892 p = page;
893 len = 0;
894 while (len < (off + count)) {
895 if ((*p == '\0') || (*p == '\n')) {
896 if (*p == '\0')
897 *p = '\n';
898 p++;
899 len++;
900 *eof = 1;
901 break;
902 }
903 p++;
904 len++;
905 }
906
907 if (len < off) {
908 *eof = 1;
909 len = 0;
910 }
911 return len;
912}
913
914#if 0
915static int mf_getVmlinuxChunk(char *buffer, int *size, int offset, u64 side)
916{
917 struct vsp_cmd_data vsp_cmd;
918 int rc;
919 int len = *size;
920 dma_addr_t dma_addr;
921
922 dma_addr = dma_map_single(iSeries_vio_dev, buffer, len,
923 DMA_FROM_DEVICE);
924 memset(buffer, 0, len);
925 memset(&vsp_cmd, 0, sizeof(vsp_cmd));
926 vsp_cmd.cmd = 32;
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;
932 mb();
933 rc = signal_vsp_instruction(&vsp_cmd);
934 if (rc == 0) {
935 if (vsp_cmd.result_code == 0)
936 *size = vsp_cmd.sub_data.length_out;
937 else
938 rc = -ENOMEM;
939 }
940
941 dma_unmap_single(iSeries_vio_dev, dma_addr, len, DMA_FROM_DEVICE);
942
943 return rc;
944}
945
946static int proc_mf_dump_vmlinux(char *page, char **start, off_t off,
947 int count, int *eof, void *data)
948{
949 int sizeToGet = count;
950
951 if (!capable(CAP_SYS_ADMIN))
952 return -EACCES;
953
954 if (mf_getVmlinuxChunk(page, &sizeToGet, off, (u64)data) == 0) {
955 if (sizeToGet != 0) {
956 *start = page + off;
957 return sizeToGet;
958 }
959 *eof = 1;
960 return 0;
961 }
962 *eof = 1;
963 return 0;
964}
965#endif
966
967static int proc_mf_dump_side(char *page, char **start, off_t off,
968 int count, int *eof, void *data)
969{
970 int len;
971 char mf_current_side = ' ';
972 struct vsp_cmd_data vsp_cmd;
973
974 memset(&vsp_cmd, 0, sizeof(vsp_cmd));
975 vsp_cmd.cmd = 2;
976 vsp_cmd.sub_data.ipl_type = 0;
977 mb();
978
979 if (signal_vsp_instruction(&vsp_cmd) == 0) {
980 if (vsp_cmd.result_code == 0) {
981 switch (vsp_cmd.sub_data.ipl_type) {
982 case 0: mf_current_side = 'A';
983 break;
984 case 1: mf_current_side = 'B';
985 break;
986 case 2: mf_current_side = 'C';
987 break;
988 default: mf_current_side = 'D';
989 break;
990 }
991 }
992 }
993
994 len = sprintf(page, "%c\n", mf_current_side);
995
996 if (len <= (off + count))
997 *eof = 1;
998 *start = page + off;
999 len -= off;
1000 if (len > count)
1001 len = count;
1002 if (len < 0)
1003 len = 0;
1004 return len;
1005}
1006
1007static int proc_mf_change_side(struct file *file, const char __user *buffer,
1008 unsigned long count, void *data)
1009{
1010 char side;
1011 u64 newSide;
1012 struct vsp_cmd_data vsp_cmd;
1013
1014 if (!capable(CAP_SYS_ADMIN))
1015 return -EACCES;
1016
1017 if (count == 0)
1018 return 0;
1019
1020 if (get_user(side, buffer))
1021 return -EFAULT;
1022
1023 switch (side) {
1024 case 'A': newSide = 0;
1025 break;
1026 case 'B': newSide = 1;
1027 break;
1028 case 'C': newSide = 2;
1029 break;
1030 case 'D': newSide = 3;
1031 break;
1032 default:
1033 printk(KERN_ERR "mf_proc.c: proc_mf_change_side: invalid side\n");
1034 return -EINVAL;
1035 }
1036
1037 memset(&vsp_cmd, 0, sizeof(vsp_cmd));
1038 vsp_cmd.sub_data.ipl_type = newSide;
1039 vsp_cmd.cmd = 10;
1040
1041 (void)signal_vsp_instruction(&vsp_cmd);
1042
1043 return count;
1044}
1045
1046#if 0
1047static void mf_getSrcHistory(char *buffer, int size)
1048{
1049 struct IplTypeReturnStuff return_stuff;
1050 struct pending_event *ev = new_pending_event();
1051 int rc = 0;
1052 char *pages[4];
1053
1054 pages[0] = kmalloc(4096, GFP_ATOMIC);
1055 pages[1] = kmalloc(4096, GFP_ATOMIC);
1056 pages[2] = kmalloc(4096, GFP_ATOMIC);
1057 pages[3] = kmalloc(4096, GFP_ATOMIC);
1058 if ((ev == NULL) || (pages[0] == NULL) || (pages[1] == NULL)
1059 || (pages[2] == NULL) || (pages[3] == NULL))
1060 return -ENOMEM;
1061
1062 return_stuff.xType = 0;
1063 return_stuff.xRc = 0;
1064 return_stuff.xDone = 0;
1065 ev->event.hp_lp_event.xSubtype = 6;
1066 ev->event.hp_lp_event.x.xSubtypeData =
1067 subtype_data('M', 'F', 'V', 'I');
1068 ev->event.data.vsp_cmd.xEvent = &return_stuff;
1069 ev->event.data.vsp_cmd.cmd = 4;
1070 ev->event.data.vsp_cmd.lp_index = HvLpConfig_getLpIndex();
1071 ev->event.data.vsp_cmd.result_code = 0xFF;
1072 ev->event.data.vsp_cmd.reserved = 0;
Stephen Rothwell426c1a12005-10-14 14:51:42 +10001073 ev->event.data.vsp_cmd.sub_data.page[0] = iseries_hv_addr(pages[0]);
1074 ev->event.data.vsp_cmd.sub_data.page[1] = iseries_hv_addr(pages[1]);
1075 ev->event.data.vsp_cmd.sub_data.page[2] = iseries_hv_addr(pages[2]);
1076 ev->event.data.vsp_cmd.sub_data.page[3] = iseries_hv_addr(pages[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 mb();
1078 if (signal_event(ev) != 0)
1079 return;
1080
1081 while (return_stuff.xDone != 1)
1082 udelay(10);
1083 if (return_stuff.xRc == 0)
1084 memcpy(buffer, pages[0], size);
1085 kfree(pages[0]);
1086 kfree(pages[1]);
1087 kfree(pages[2]);
1088 kfree(pages[3]);
1089}
1090#endif
1091
1092static int proc_mf_dump_src(char *page, char **start, off_t off,
1093 int count, int *eof, void *data)
1094{
1095#if 0
1096 int len;
1097
1098 mf_getSrcHistory(page, count);
1099 len = count;
1100 len -= off;
1101 if (len < count) {
1102 *eof = 1;
1103 if (len <= 0)
1104 return 0;
1105 } else
1106 len = count;
1107 *start = page + off;
1108 return len;
1109#else
1110 return 0;
1111#endif
1112}
1113
1114static int proc_mf_change_src(struct file *file, const char __user *buffer,
1115 unsigned long count, void *data)
1116{
1117 char stkbuf[10];
1118
1119 if (!capable(CAP_SYS_ADMIN))
1120 return -EACCES;
1121
1122 if ((count < 4) && (count != 1)) {
1123 printk(KERN_ERR "mf_proc: invalid src\n");
1124 return -EINVAL;
1125 }
1126
1127 if (count > (sizeof(stkbuf) - 1))
1128 count = sizeof(stkbuf) - 1;
1129 if (copy_from_user(stkbuf, buffer, count))
1130 return -EFAULT;
1131
1132 if ((count == 1) && (*stkbuf == '\0'))
1133 mf_clear_src();
1134 else
1135 mf_display_src(*(u32 *)stkbuf);
1136
1137 return count;
1138}
1139
1140static int proc_mf_change_cmdline(struct file *file, const char __user *buffer,
1141 unsigned long count, void *data)
1142{
1143 struct vsp_cmd_data vsp_cmd;
1144 dma_addr_t dma_addr;
1145 char *page;
1146 int ret = -EACCES;
1147
1148 if (!capable(CAP_SYS_ADMIN))
1149 goto out;
1150
1151 dma_addr = 0;
1152 page = dma_alloc_coherent(iSeries_vio_dev, count, &dma_addr,
1153 GFP_ATOMIC);
1154 ret = -ENOMEM;
1155 if (page == NULL)
1156 goto out;
1157
1158 ret = -EFAULT;
1159 if (copy_from_user(page, buffer, count))
1160 goto out_free;
1161
1162 memset(&vsp_cmd, 0, sizeof(vsp_cmd));
1163 vsp_cmd.cmd = 31;
1164 vsp_cmd.sub_data.kern.token = dma_addr;
1165 vsp_cmd.sub_data.kern.address_type = HvLpDma_AddressType_TceIndex;
1166 vsp_cmd.sub_data.kern.side = (u64)data;
1167 vsp_cmd.sub_data.kern.length = count;
1168 mb();
1169 (void)signal_vsp_instruction(&vsp_cmd);
1170 ret = count;
1171
1172out_free:
1173 dma_free_coherent(iSeries_vio_dev, count, page, dma_addr);
1174out:
1175 return ret;
1176}
1177
1178static ssize_t proc_mf_change_vmlinux(struct file *file,
1179 const char __user *buf,
1180 size_t count, loff_t *ppos)
1181{
1182 struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode);
1183 ssize_t rc;
1184 dma_addr_t dma_addr;
1185 char *page;
1186 struct vsp_cmd_data vsp_cmd;
1187
1188 rc = -EACCES;
1189 if (!capable(CAP_SYS_ADMIN))
1190 goto out;
1191
1192 dma_addr = 0;
1193 page = dma_alloc_coherent(iSeries_vio_dev, count, &dma_addr,
1194 GFP_ATOMIC);
1195 rc = -ENOMEM;
1196 if (page == NULL) {
1197 printk(KERN_ERR "mf.c: couldn't allocate memory to set vmlinux chunk\n");
1198 goto out;
1199 }
1200 rc = -EFAULT;
1201 if (copy_from_user(page, buf, count))
1202 goto out_free;
1203
1204 memset(&vsp_cmd, 0, sizeof(vsp_cmd));
1205 vsp_cmd.cmd = 30;
1206 vsp_cmd.sub_data.kern.token = dma_addr;
1207 vsp_cmd.sub_data.kern.address_type = HvLpDma_AddressType_TceIndex;
1208 vsp_cmd.sub_data.kern.side = (u64)dp->data;
1209 vsp_cmd.sub_data.kern.offset = *ppos;
1210 vsp_cmd.sub_data.kern.length = count;
1211 mb();
1212 rc = signal_vsp_instruction(&vsp_cmd);
1213 if (rc)
1214 goto out_free;
1215 rc = -ENOMEM;
1216 if (vsp_cmd.result_code != 0)
1217 goto out_free;
1218
1219 *ppos += count;
1220 rc = count;
1221out_free:
1222 dma_free_coherent(iSeries_vio_dev, count, page, dma_addr);
1223out:
1224 return rc;
1225}
1226
1227static struct file_operations proc_vmlinux_operations = {
1228 .write = proc_mf_change_vmlinux,
1229};
1230
1231static int __init mf_proc_init(void)
1232{
1233 struct proc_dir_entry *mf_proc_root;
1234 struct proc_dir_entry *ent;
1235 struct proc_dir_entry *mf;
1236 char name[2];
1237 int i;
1238
1239 mf_proc_root = proc_mkdir("iSeries/mf", NULL);
1240 if (!mf_proc_root)
1241 return 1;
1242
1243 name[1] = '\0';
1244 for (i = 0; i < 4; i++) {
1245 name[0] = 'A' + i;
1246 mf = proc_mkdir(name, mf_proc_root);
1247 if (!mf)
1248 return 1;
1249
1250 ent = create_proc_entry("cmdline", S_IFREG|S_IRUSR|S_IWUSR, mf);
1251 if (!ent)
1252 return 1;
1253 ent->nlink = 1;
1254 ent->data = (void *)(long)i;
1255 ent->read_proc = proc_mf_dump_cmdline;
1256 ent->write_proc = proc_mf_change_cmdline;
1257
1258 if (i == 3) /* no vmlinux entry for 'D' */
1259 continue;
1260
1261 ent = create_proc_entry("vmlinux", S_IFREG|S_IWUSR, mf);
1262 if (!ent)
1263 return 1;
1264 ent->nlink = 1;
1265 ent->data = (void *)(long)i;
1266 ent->proc_fops = &proc_vmlinux_operations;
1267 }
1268
1269 ent = create_proc_entry("side", S_IFREG|S_IRUSR|S_IWUSR, mf_proc_root);
1270 if (!ent)
1271 return 1;
1272 ent->nlink = 1;
1273 ent->data = (void *)0;
1274 ent->read_proc = proc_mf_dump_side;
1275 ent->write_proc = proc_mf_change_side;
1276
1277 ent = create_proc_entry("src", S_IFREG|S_IRUSR|S_IWUSR, mf_proc_root);
1278 if (!ent)
1279 return 1;
1280 ent->nlink = 1;
1281 ent->data = (void *)0;
1282 ent->read_proc = proc_mf_dump_src;
1283 ent->write_proc = proc_mf_change_src;
1284
1285 return 0;
1286}
1287
1288__initcall(mf_proc_init);
1289
1290#endif /* CONFIG_PROC_FS */
Stephen Rothwellc8b84972005-09-27 18:44:42 +10001291
1292/*
1293 * Get the RTC from the virtual service processor
1294 * This requires flowing LpEvents to the primary partition
1295 */
1296void iSeries_get_rtc_time(struct rtc_time *rtc_tm)
1297{
1298 if (piranha_simulator)
1299 return;
1300
1301 mf_get_rtc(rtc_tm);
1302 rtc_tm->tm_mon--;
1303}
1304
1305/*
1306 * Set the RTC in the virtual service processor
1307 * This requires flowing LpEvents to the primary partition
1308 */
1309int iSeries_set_rtc_time(struct rtc_time *tm)
1310{
1311 mf_set_rtc(tm);
1312 return 0;
1313}
1314
Paul Mackerras143a1de2005-10-19 23:11:21 +10001315unsigned long iSeries_get_boot_time(void)
Stephen Rothwellc8b84972005-09-27 18:44:42 +10001316{
Paul Mackerras143a1de2005-10-19 23:11:21 +10001317 struct rtc_time tm;
Stephen Rothwellc8b84972005-09-27 18:44:42 +10001318
Paul Mackerras143a1de2005-10-19 23:11:21 +10001319 if (piranha_simulator)
1320 return 0;
1321
1322 mf_get_boot_rtc(&tm);
1323 return mktime(tm.tm_year + 1900, tm.tm_mon, tm.tm_mday,
1324 tm.tm_hour, tm.tm_min, tm.tm_sec);
Stephen Rothwellc8b84972005-09-27 18:44:42 +10001325}