mf.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311
  1. /*
  2. * 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. */
  26. #include <linux/types.h>
  27. #include <linux/errno.h>
  28. #include <linux/kernel.h>
  29. #include <linux/init.h>
  30. #include <linux/completion.h>
  31. #include <linux/delay.h>
  32. #include <linux/dma-mapping.h>
  33. #include <linux/bcd.h>
  34. #include <linux/rtc.h>
  35. #include <asm/time.h>
  36. #include <asm/uaccess.h>
  37. #include <asm/paca.h>
  38. #include <asm/abs_addr.h>
  39. #include <asm/iseries/vio.h>
  40. #include <asm/iseries/mf.h>
  41. #include <asm/iseries/hv_lp_config.h>
  42. #include <asm/iseries/it_lp_queue.h>
  43. #include "setup.h"
  44. extern int piranha_simulator;
  45. /*
  46. * This is the structure layout for the Machine Facilites LPAR event
  47. * flows.
  48. */
  49. struct vsp_cmd_data {
  50. u64 token;
  51. u16 cmd;
  52. HvLpIndex lp_index;
  53. u8 result_code;
  54. u32 reserved;
  55. union {
  56. u64 state; /* GetStateOut */
  57. u64 ipl_type; /* GetIplTypeOut, Function02SelectIplTypeIn */
  58. u64 ipl_mode; /* GetIplModeOut, Function02SelectIplModeIn */
  59. u64 page[4]; /* GetSrcHistoryIn */
  60. u64 flag; /* GetAutoIplWhenPrimaryIplsOut,
  61. SetAutoIplWhenPrimaryIplsIn,
  62. WhiteButtonPowerOffIn,
  63. Function08FastPowerOffIn,
  64. IsSpcnRackPowerIncompleteOut */
  65. struct {
  66. u64 token;
  67. u64 address_type;
  68. u64 side;
  69. u32 length;
  70. u32 offset;
  71. } kern; /* SetKernelImageIn, GetKernelImageIn,
  72. SetKernelCmdLineIn, GetKernelCmdLineIn */
  73. u32 length_out; /* GetKernelImageOut, GetKernelCmdLineOut */
  74. u8 reserved[80];
  75. } sub_data;
  76. };
  77. struct vsp_rsp_data {
  78. struct completion com;
  79. struct vsp_cmd_data *response;
  80. };
  81. struct alloc_data {
  82. u16 size;
  83. u16 type;
  84. u32 count;
  85. u16 reserved1;
  86. u8 reserved2;
  87. HvLpIndex target_lp;
  88. };
  89. struct ce_msg_data;
  90. typedef void (*ce_msg_comp_hdlr)(void *token, struct ce_msg_data *vsp_cmd_rsp);
  91. struct ce_msg_comp_data {
  92. ce_msg_comp_hdlr handler;
  93. void *token;
  94. };
  95. struct ce_msg_data {
  96. u8 ce_msg[12];
  97. char reserved[4];
  98. struct ce_msg_comp_data *completion;
  99. };
  100. struct io_mf_lp_event {
  101. struct HvLpEvent hp_lp_event;
  102. u16 subtype_result_code;
  103. u16 reserved1;
  104. u32 reserved2;
  105. union {
  106. struct alloc_data alloc;
  107. struct ce_msg_data ce_msg;
  108. struct vsp_cmd_data vsp_cmd;
  109. } data;
  110. };
  111. #define subtype_data(a, b, c, d) \
  112. (((a) << 24) + ((b) << 16) + ((c) << 8) + (d))
  113. /*
  114. * All outgoing event traffic is kept on a FIFO queue. The first
  115. * pointer points to the one that is outstanding, and all new
  116. * requests get stuck on the end. Also, we keep a certain number of
  117. * preallocated pending events so that we can operate very early in
  118. * the boot up sequence (before kmalloc is ready).
  119. */
  120. struct pending_event {
  121. struct pending_event *next;
  122. struct io_mf_lp_event event;
  123. MFCompleteHandler hdlr;
  124. char dma_data[72];
  125. unsigned dma_data_length;
  126. unsigned remote_address;
  127. };
  128. static spinlock_t pending_event_spinlock;
  129. static struct pending_event *pending_event_head;
  130. static struct pending_event *pending_event_tail;
  131. static struct pending_event *pending_event_avail;
  132. static struct pending_event pending_event_prealloc[16];
  133. /*
  134. * Put a pending event onto the available queue, so it can get reused.
  135. * Attention! You must have the pending_event_spinlock before calling!
  136. */
  137. static void free_pending_event(struct pending_event *ev)
  138. {
  139. if (ev != NULL) {
  140. ev->next = pending_event_avail;
  141. pending_event_avail = ev;
  142. }
  143. }
  144. /*
  145. * Enqueue the outbound event onto the stack. If the queue was
  146. * empty to begin with, we must also issue it via the Hypervisor
  147. * interface. There is a section of code below that will touch
  148. * the first stack pointer without the protection of the pending_event_spinlock.
  149. * This is OK, because we know that nobody else will be modifying
  150. * the first pointer when we do this.
  151. */
  152. static int signal_event(struct pending_event *ev)
  153. {
  154. int rc = 0;
  155. unsigned long flags;
  156. int go = 1;
  157. struct pending_event *ev1;
  158. HvLpEvent_Rc hv_rc;
  159. /* enqueue the event */
  160. if (ev != NULL) {
  161. ev->next = NULL;
  162. spin_lock_irqsave(&pending_event_spinlock, flags);
  163. if (pending_event_head == NULL)
  164. pending_event_head = ev;
  165. else {
  166. go = 0;
  167. pending_event_tail->next = ev;
  168. }
  169. pending_event_tail = ev;
  170. spin_unlock_irqrestore(&pending_event_spinlock, flags);
  171. }
  172. /* send the event */
  173. while (go) {
  174. go = 0;
  175. /* any DMA data to send beforehand? */
  176. if (pending_event_head->dma_data_length > 0)
  177. HvCallEvent_dmaToSp(pending_event_head->dma_data,
  178. pending_event_head->remote_address,
  179. pending_event_head->dma_data_length,
  180. HvLpDma_Direction_LocalToRemote);
  181. hv_rc = HvCallEvent_signalLpEvent(
  182. &pending_event_head->event.hp_lp_event);
  183. if (hv_rc != HvLpEvent_Rc_Good) {
  184. printk(KERN_ERR "mf.c: HvCallEvent_signalLpEvent() "
  185. "failed with %d\n", (int)hv_rc);
  186. spin_lock_irqsave(&pending_event_spinlock, flags);
  187. ev1 = pending_event_head;
  188. pending_event_head = pending_event_head->next;
  189. if (pending_event_head != NULL)
  190. go = 1;
  191. spin_unlock_irqrestore(&pending_event_spinlock, flags);
  192. if (ev1 == ev)
  193. rc = -EIO;
  194. else if (ev1->hdlr != NULL)
  195. (*ev1->hdlr)((void *)ev1->event.hp_lp_event.xCorrelationToken, -EIO);
  196. spin_lock_irqsave(&pending_event_spinlock, flags);
  197. free_pending_event(ev1);
  198. spin_unlock_irqrestore(&pending_event_spinlock, flags);
  199. }
  200. }
  201. return rc;
  202. }
  203. /*
  204. * Allocate a new pending_event structure, and initialize it.
  205. */
  206. static struct pending_event *new_pending_event(void)
  207. {
  208. struct pending_event *ev = NULL;
  209. HvLpIndex primary_lp = HvLpConfig_getPrimaryLpIndex();
  210. unsigned long flags;
  211. struct HvLpEvent *hev;
  212. spin_lock_irqsave(&pending_event_spinlock, flags);
  213. if (pending_event_avail != NULL) {
  214. ev = pending_event_avail;
  215. pending_event_avail = pending_event_avail->next;
  216. }
  217. spin_unlock_irqrestore(&pending_event_spinlock, flags);
  218. if (ev == NULL) {
  219. ev = kmalloc(sizeof(struct pending_event), GFP_ATOMIC);
  220. if (ev == NULL) {
  221. printk(KERN_ERR "mf.c: unable to kmalloc %ld bytes\n",
  222. sizeof(struct pending_event));
  223. return NULL;
  224. }
  225. }
  226. memset(ev, 0, sizeof(struct pending_event));
  227. hev = &ev->event.hp_lp_event;
  228. hev->flags = HV_LP_EVENT_VALID | HV_LP_EVENT_DO_ACK | HV_LP_EVENT_INT;
  229. hev->xType = HvLpEvent_Type_MachineFac;
  230. hev->xSourceLp = HvLpConfig_getLpIndex();
  231. hev->xTargetLp = primary_lp;
  232. hev->xSizeMinus1 = sizeof(ev->event) - 1;
  233. hev->xRc = HvLpEvent_Rc_Good;
  234. hev->xSourceInstanceId = HvCallEvent_getSourceLpInstanceId(primary_lp,
  235. HvLpEvent_Type_MachineFac);
  236. hev->xTargetInstanceId = HvCallEvent_getTargetLpInstanceId(primary_lp,
  237. HvLpEvent_Type_MachineFac);
  238. return ev;
  239. }
  240. static int signal_vsp_instruction(struct vsp_cmd_data *vsp_cmd)
  241. {
  242. struct pending_event *ev = new_pending_event();
  243. int rc;
  244. struct vsp_rsp_data response;
  245. if (ev == NULL)
  246. return -ENOMEM;
  247. init_completion(&response.com);
  248. response.response = vsp_cmd;
  249. ev->event.hp_lp_event.xSubtype = 6;
  250. ev->event.hp_lp_event.x.xSubtypeData =
  251. subtype_data('M', 'F', 'V', 'I');
  252. ev->event.data.vsp_cmd.token = (u64)&response;
  253. ev->event.data.vsp_cmd.cmd = vsp_cmd->cmd;
  254. ev->event.data.vsp_cmd.lp_index = HvLpConfig_getLpIndex();
  255. ev->event.data.vsp_cmd.result_code = 0xFF;
  256. ev->event.data.vsp_cmd.reserved = 0;
  257. memcpy(&(ev->event.data.vsp_cmd.sub_data),
  258. &(vsp_cmd->sub_data), sizeof(vsp_cmd->sub_data));
  259. mb();
  260. rc = signal_event(ev);
  261. if (rc == 0)
  262. wait_for_completion(&response.com);
  263. return rc;
  264. }
  265. /*
  266. * Send a 12-byte CE message to the primary partition VSP object
  267. */
  268. static int signal_ce_msg(char *ce_msg, struct ce_msg_comp_data *completion)
  269. {
  270. struct pending_event *ev = new_pending_event();
  271. if (ev == NULL)
  272. return -ENOMEM;
  273. ev->event.hp_lp_event.xSubtype = 0;
  274. ev->event.hp_lp_event.x.xSubtypeData =
  275. subtype_data('M', 'F', 'C', 'E');
  276. memcpy(ev->event.data.ce_msg.ce_msg, ce_msg, 12);
  277. ev->event.data.ce_msg.completion = completion;
  278. return signal_event(ev);
  279. }
  280. /*
  281. * Send a 12-byte CE message (with no data) to the primary partition VSP object
  282. */
  283. static int signal_ce_msg_simple(u8 ce_op, struct ce_msg_comp_data *completion)
  284. {
  285. u8 ce_msg[12];
  286. memset(ce_msg, 0, sizeof(ce_msg));
  287. ce_msg[3] = ce_op;
  288. return signal_ce_msg(ce_msg, completion);
  289. }
  290. /*
  291. * Send a 12-byte CE message and DMA data to the primary partition VSP object
  292. */
  293. static int dma_and_signal_ce_msg(char *ce_msg,
  294. struct ce_msg_comp_data *completion, void *dma_data,
  295. unsigned dma_data_length, unsigned remote_address)
  296. {
  297. struct pending_event *ev = new_pending_event();
  298. if (ev == NULL)
  299. return -ENOMEM;
  300. ev->event.hp_lp_event.xSubtype = 0;
  301. ev->event.hp_lp_event.x.xSubtypeData =
  302. subtype_data('M', 'F', 'C', 'E');
  303. memcpy(ev->event.data.ce_msg.ce_msg, ce_msg, 12);
  304. ev->event.data.ce_msg.completion = completion;
  305. memcpy(ev->dma_data, dma_data, dma_data_length);
  306. ev->dma_data_length = dma_data_length;
  307. ev->remote_address = remote_address;
  308. return signal_event(ev);
  309. }
  310. /*
  311. * Initiate a nice (hopefully) shutdown of Linux. We simply are
  312. * going to try and send the init process a SIGINT signal. If
  313. * this fails (why?), we'll simply force it off in a not-so-nice
  314. * manner.
  315. */
  316. static int shutdown(void)
  317. {
  318. int rc = kill_proc(1, SIGINT, 1);
  319. if (rc) {
  320. printk(KERN_ALERT "mf.c: SIGINT to init failed (%d), "
  321. "hard shutdown commencing\n", rc);
  322. mf_power_off();
  323. } else
  324. printk(KERN_INFO "mf.c: init has been successfully notified "
  325. "to proceed with shutdown\n");
  326. return rc;
  327. }
  328. /*
  329. * The primary partition VSP object is sending us a new
  330. * event flow. Handle it...
  331. */
  332. static void handle_int(struct io_mf_lp_event *event)
  333. {
  334. struct ce_msg_data *ce_msg_data;
  335. struct ce_msg_data *pce_msg_data;
  336. unsigned long flags;
  337. struct pending_event *pev;
  338. /* ack the interrupt */
  339. event->hp_lp_event.xRc = HvLpEvent_Rc_Good;
  340. HvCallEvent_ackLpEvent(&event->hp_lp_event);
  341. /* process interrupt */
  342. switch (event->hp_lp_event.xSubtype) {
  343. case 0: /* CE message */
  344. ce_msg_data = &event->data.ce_msg;
  345. switch (ce_msg_data->ce_msg[3]) {
  346. case 0x5B: /* power control notification */
  347. if ((ce_msg_data->ce_msg[5] & 0x20) != 0) {
  348. printk(KERN_INFO "mf.c: Commencing partition shutdown\n");
  349. if (shutdown() == 0)
  350. signal_ce_msg_simple(0xDB, NULL);
  351. }
  352. break;
  353. case 0xC0: /* get time */
  354. spin_lock_irqsave(&pending_event_spinlock, flags);
  355. pev = pending_event_head;
  356. if (pev != NULL)
  357. pending_event_head = pending_event_head->next;
  358. spin_unlock_irqrestore(&pending_event_spinlock, flags);
  359. if (pev == NULL)
  360. break;
  361. pce_msg_data = &pev->event.data.ce_msg;
  362. if (pce_msg_data->ce_msg[3] != 0x40)
  363. break;
  364. if (pce_msg_data->completion != NULL) {
  365. ce_msg_comp_hdlr handler =
  366. pce_msg_data->completion->handler;
  367. void *token = pce_msg_data->completion->token;
  368. if (handler != NULL)
  369. (*handler)(token, ce_msg_data);
  370. }
  371. spin_lock_irqsave(&pending_event_spinlock, flags);
  372. free_pending_event(pev);
  373. spin_unlock_irqrestore(&pending_event_spinlock, flags);
  374. /* send next waiting event */
  375. if (pending_event_head != NULL)
  376. signal_event(NULL);
  377. break;
  378. }
  379. break;
  380. case 1: /* IT sys shutdown */
  381. printk(KERN_INFO "mf.c: Commencing system shutdown\n");
  382. shutdown();
  383. break;
  384. }
  385. }
  386. /*
  387. * The primary partition VSP object is acknowledging the receipt
  388. * of a flow we sent to them. If there are other flows queued
  389. * up, we must send another one now...
  390. */
  391. static void handle_ack(struct io_mf_lp_event *event)
  392. {
  393. unsigned long flags;
  394. struct pending_event *two = NULL;
  395. unsigned long free_it = 0;
  396. struct ce_msg_data *ce_msg_data;
  397. struct ce_msg_data *pce_msg_data;
  398. struct vsp_rsp_data *rsp;
  399. /* handle current event */
  400. if (pending_event_head == NULL) {
  401. printk(KERN_ERR "mf.c: stack empty for receiving ack\n");
  402. return;
  403. }
  404. switch (event->hp_lp_event.xSubtype) {
  405. case 0: /* CE msg */
  406. ce_msg_data = &event->data.ce_msg;
  407. if (ce_msg_data->ce_msg[3] != 0x40) {
  408. free_it = 1;
  409. break;
  410. }
  411. if (ce_msg_data->ce_msg[2] == 0)
  412. break;
  413. free_it = 1;
  414. pce_msg_data = &pending_event_head->event.data.ce_msg;
  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;
  419. if (handler != NULL)
  420. (*handler)(token, ce_msg_data);
  421. }
  422. break;
  423. case 4: /* allocate */
  424. case 5: /* deallocate */
  425. if (pending_event_head->hdlr != NULL)
  426. (*pending_event_head->hdlr)((void *)event->hp_lp_event.xCorrelationToken, event->data.alloc.count);
  427. free_it = 1;
  428. break;
  429. case 6:
  430. free_it = 1;
  431. rsp = (struct vsp_rsp_data *)event->data.vsp_cmd.token;
  432. if (rsp == NULL) {
  433. printk(KERN_ERR "mf.c: no rsp\n");
  434. break;
  435. }
  436. if (rsp->response != NULL)
  437. memcpy(rsp->response, &event->data.vsp_cmd,
  438. sizeof(event->data.vsp_cmd));
  439. complete(&rsp->com);
  440. break;
  441. }
  442. /* remove from queue */
  443. spin_lock_irqsave(&pending_event_spinlock, flags);
  444. if ((pending_event_head != NULL) && (free_it == 1)) {
  445. struct pending_event *oldHead = pending_event_head;
  446. pending_event_head = pending_event_head->next;
  447. two = pending_event_head;
  448. free_pending_event(oldHead);
  449. }
  450. spin_unlock_irqrestore(&pending_event_spinlock, flags);
  451. /* send next waiting event */
  452. if (two != NULL)
  453. signal_event(NULL);
  454. }
  455. /*
  456. * This is the generic event handler we are registering with
  457. * the Hypervisor. Ensure the flows are for us, and then
  458. * parse it enough to know if it is an interrupt or an
  459. * acknowledge.
  460. */
  461. static void hv_handler(struct HvLpEvent *event, struct pt_regs *regs)
  462. {
  463. if ((event != NULL) && (event->xType == HvLpEvent_Type_MachineFac)) {
  464. if (hvlpevent_is_ack(event))
  465. handle_ack((struct io_mf_lp_event *)event);
  466. else
  467. handle_int((struct io_mf_lp_event *)event);
  468. } else
  469. printk(KERN_ERR "mf.c: alien event received\n");
  470. }
  471. /*
  472. * Global kernel interface to allocate and seed events into the
  473. * Hypervisor.
  474. */
  475. void mf_allocate_lp_events(HvLpIndex target_lp, HvLpEvent_Type type,
  476. unsigned size, unsigned count, MFCompleteHandler hdlr,
  477. void *user_token)
  478. {
  479. struct pending_event *ev = new_pending_event();
  480. int rc;
  481. if (ev == NULL) {
  482. rc = -ENOMEM;
  483. } else {
  484. ev->event.hp_lp_event.xSubtype = 4;
  485. ev->event.hp_lp_event.xCorrelationToken = (u64)user_token;
  486. ev->event.hp_lp_event.x.xSubtypeData =
  487. subtype_data('M', 'F', 'M', 'A');
  488. ev->event.data.alloc.target_lp = target_lp;
  489. ev->event.data.alloc.type = type;
  490. ev->event.data.alloc.size = size;
  491. ev->event.data.alloc.count = count;
  492. ev->hdlr = hdlr;
  493. rc = signal_event(ev);
  494. }
  495. if ((rc != 0) && (hdlr != NULL))
  496. (*hdlr)(user_token, rc);
  497. }
  498. EXPORT_SYMBOL(mf_allocate_lp_events);
  499. /*
  500. * Global kernel interface to unseed and deallocate events already in
  501. * Hypervisor.
  502. */
  503. void mf_deallocate_lp_events(HvLpIndex target_lp, HvLpEvent_Type type,
  504. unsigned count, MFCompleteHandler hdlr, void *user_token)
  505. {
  506. struct pending_event *ev = new_pending_event();
  507. int rc;
  508. if (ev == NULL)
  509. rc = -ENOMEM;
  510. else {
  511. ev->event.hp_lp_event.xSubtype = 5;
  512. ev->event.hp_lp_event.xCorrelationToken = (u64)user_token;
  513. ev->event.hp_lp_event.x.xSubtypeData =
  514. subtype_data('M', 'F', 'M', 'D');
  515. ev->event.data.alloc.target_lp = target_lp;
  516. ev->event.data.alloc.type = type;
  517. ev->event.data.alloc.count = count;
  518. ev->hdlr = hdlr;
  519. rc = signal_event(ev);
  520. }
  521. if ((rc != 0) && (hdlr != NULL))
  522. (*hdlr)(user_token, rc);
  523. }
  524. EXPORT_SYMBOL(mf_deallocate_lp_events);
  525. /*
  526. * Global kernel interface to tell the VSP object in the primary
  527. * partition to power this partition off.
  528. */
  529. void mf_power_off(void)
  530. {
  531. printk(KERN_INFO "mf.c: Down it goes...\n");
  532. signal_ce_msg_simple(0x4d, NULL);
  533. for (;;)
  534. ;
  535. }
  536. /*
  537. * Global kernel interface to tell the VSP object in the primary
  538. * partition to reboot this partition.
  539. */
  540. void mf_reboot(void)
  541. {
  542. printk(KERN_INFO "mf.c: Preparing to bounce...\n");
  543. signal_ce_msg_simple(0x4e, NULL);
  544. for (;;)
  545. ;
  546. }
  547. /*
  548. * Display a single word SRC onto the VSP control panel.
  549. */
  550. void mf_display_src(u32 word)
  551. {
  552. u8 ce[12];
  553. memset(ce, 0, sizeof(ce));
  554. ce[3] = 0x4a;
  555. ce[7] = 0x01;
  556. ce[8] = word >> 24;
  557. ce[9] = word >> 16;
  558. ce[10] = word >> 8;
  559. ce[11] = word;
  560. signal_ce_msg(ce, NULL);
  561. }
  562. /*
  563. * Display a single word SRC of the form "PROGXXXX" on the VSP control panel.
  564. */
  565. void mf_display_progress(u16 value)
  566. {
  567. u8 ce[12];
  568. u8 src[72];
  569. memcpy(ce, "\x00\x00\x04\x4A\x00\x00\x00\x48\x00\x00\x00\x00", 12);
  570. memcpy(src, "\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00"
  571. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  572. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  573. "\x00\x00\x00\x00PROGxxxx ",
  574. 72);
  575. src[6] = value >> 8;
  576. src[7] = value & 255;
  577. src[44] = "0123456789ABCDEF"[(value >> 12) & 15];
  578. src[45] = "0123456789ABCDEF"[(value >> 8) & 15];
  579. src[46] = "0123456789ABCDEF"[(value >> 4) & 15];
  580. src[47] = "0123456789ABCDEF"[value & 15];
  581. dma_and_signal_ce_msg(ce, NULL, src, sizeof(src), 9 * 64 * 1024);
  582. }
  583. /*
  584. * Clear the VSP control panel. Used to "erase" an SRC that was
  585. * previously displayed.
  586. */
  587. void mf_clear_src(void)
  588. {
  589. signal_ce_msg_simple(0x4b, NULL);
  590. }
  591. /*
  592. * Initialization code here.
  593. */
  594. void mf_init(void)
  595. {
  596. int i;
  597. /* initialize */
  598. spin_lock_init(&pending_event_spinlock);
  599. for (i = 0;
  600. i < sizeof(pending_event_prealloc) / sizeof(*pending_event_prealloc);
  601. ++i)
  602. free_pending_event(&pending_event_prealloc[i]);
  603. HvLpEvent_registerHandler(HvLpEvent_Type_MachineFac, &hv_handler);
  604. /* virtual continue ack */
  605. signal_ce_msg_simple(0x57, NULL);
  606. /* initialization complete */
  607. printk(KERN_NOTICE "mf.c: iSeries Linux LPAR Machine Facilities "
  608. "initialized\n");
  609. }
  610. struct rtc_time_data {
  611. struct completion com;
  612. struct ce_msg_data ce_msg;
  613. int rc;
  614. };
  615. static void get_rtc_time_complete(void *token, struct ce_msg_data *ce_msg)
  616. {
  617. struct rtc_time_data *rtc = token;
  618. memcpy(&rtc->ce_msg, ce_msg, sizeof(rtc->ce_msg));
  619. rtc->rc = 0;
  620. complete(&rtc->com);
  621. }
  622. static int rtc_set_tm(int rc, u8 *ce_msg, struct rtc_time *tm)
  623. {
  624. tm->tm_wday = 0;
  625. tm->tm_yday = 0;
  626. tm->tm_isdst = 0;
  627. if (rc) {
  628. tm->tm_sec = 0;
  629. tm->tm_min = 0;
  630. tm->tm_hour = 0;
  631. tm->tm_mday = 15;
  632. tm->tm_mon = 5;
  633. tm->tm_year = 52;
  634. return rc;
  635. }
  636. if ((ce_msg[2] == 0xa9) ||
  637. (ce_msg[2] == 0xaf)) {
  638. /* TOD clock is not set */
  639. tm->tm_sec = 1;
  640. tm->tm_min = 1;
  641. tm->tm_hour = 1;
  642. tm->tm_mday = 10;
  643. tm->tm_mon = 8;
  644. tm->tm_year = 71;
  645. mf_set_rtc(tm);
  646. }
  647. {
  648. u8 year = ce_msg[5];
  649. u8 sec = ce_msg[6];
  650. u8 min = ce_msg[7];
  651. u8 hour = ce_msg[8];
  652. u8 day = ce_msg[10];
  653. u8 mon = ce_msg[11];
  654. BCD_TO_BIN(sec);
  655. BCD_TO_BIN(min);
  656. BCD_TO_BIN(hour);
  657. BCD_TO_BIN(day);
  658. BCD_TO_BIN(mon);
  659. BCD_TO_BIN(year);
  660. if (year <= 69)
  661. year += 100;
  662. tm->tm_sec = sec;
  663. tm->tm_min = min;
  664. tm->tm_hour = hour;
  665. tm->tm_mday = day;
  666. tm->tm_mon = mon;
  667. tm->tm_year = year;
  668. }
  669. return 0;
  670. }
  671. int mf_get_rtc(struct rtc_time *tm)
  672. {
  673. struct ce_msg_comp_data ce_complete;
  674. struct rtc_time_data rtc_data;
  675. int rc;
  676. memset(&ce_complete, 0, sizeof(ce_complete));
  677. memset(&rtc_data, 0, sizeof(rtc_data));
  678. init_completion(&rtc_data.com);
  679. ce_complete.handler = &get_rtc_time_complete;
  680. ce_complete.token = &rtc_data;
  681. rc = signal_ce_msg_simple(0x40, &ce_complete);
  682. if (rc)
  683. return rc;
  684. wait_for_completion(&rtc_data.com);
  685. return rtc_set_tm(rtc_data.rc, rtc_data.ce_msg.ce_msg, tm);
  686. }
  687. struct boot_rtc_time_data {
  688. int busy;
  689. struct ce_msg_data ce_msg;
  690. int rc;
  691. };
  692. static void get_boot_rtc_time_complete(void *token, struct ce_msg_data *ce_msg)
  693. {
  694. struct boot_rtc_time_data *rtc = token;
  695. memcpy(&rtc->ce_msg, ce_msg, sizeof(rtc->ce_msg));
  696. rtc->rc = 0;
  697. rtc->busy = 0;
  698. }
  699. int mf_get_boot_rtc(struct rtc_time *tm)
  700. {
  701. struct ce_msg_comp_data ce_complete;
  702. struct boot_rtc_time_data rtc_data;
  703. int rc;
  704. memset(&ce_complete, 0, sizeof(ce_complete));
  705. memset(&rtc_data, 0, sizeof(rtc_data));
  706. rtc_data.busy = 1;
  707. ce_complete.handler = &get_boot_rtc_time_complete;
  708. ce_complete.token = &rtc_data;
  709. rc = signal_ce_msg_simple(0x40, &ce_complete);
  710. if (rc)
  711. return rc;
  712. /* We need to poll here as we are not yet taking interrupts */
  713. while (rtc_data.busy) {
  714. if (hvlpevent_is_pending())
  715. process_hvlpevents(NULL);
  716. }
  717. return rtc_set_tm(rtc_data.rc, rtc_data.ce_msg.ce_msg, tm);
  718. }
  719. int mf_set_rtc(struct rtc_time *tm)
  720. {
  721. char ce_time[12];
  722. u8 day, mon, hour, min, sec, y1, y2;
  723. unsigned year;
  724. year = 1900 + tm->tm_year;
  725. y1 = year / 100;
  726. y2 = year % 100;
  727. sec = tm->tm_sec;
  728. min = tm->tm_min;
  729. hour = tm->tm_hour;
  730. day = tm->tm_mday;
  731. mon = tm->tm_mon + 1;
  732. BIN_TO_BCD(sec);
  733. BIN_TO_BCD(min);
  734. BIN_TO_BCD(hour);
  735. BIN_TO_BCD(mon);
  736. BIN_TO_BCD(day);
  737. BIN_TO_BCD(y1);
  738. BIN_TO_BCD(y2);
  739. memset(ce_time, 0, sizeof(ce_time));
  740. ce_time[3] = 0x41;
  741. ce_time[4] = y1;
  742. ce_time[5] = y2;
  743. ce_time[6] = sec;
  744. ce_time[7] = min;
  745. ce_time[8] = hour;
  746. ce_time[10] = day;
  747. ce_time[11] = mon;
  748. return signal_ce_msg(ce_time, NULL);
  749. }
  750. #ifdef CONFIG_PROC_FS
  751. static int proc_mf_dump_cmdline(char *page, char **start, off_t off,
  752. int count, int *eof, void *data)
  753. {
  754. int len;
  755. char *p;
  756. struct vsp_cmd_data vsp_cmd;
  757. int rc;
  758. dma_addr_t dma_addr;
  759. /* The HV appears to return no more than 256 bytes of command line */
  760. if (off >= 256)
  761. return 0;
  762. if ((off + count) > 256)
  763. count = 256 - off;
  764. dma_addr = dma_map_single(iSeries_vio_dev, page, off + count,
  765. DMA_FROM_DEVICE);
  766. if (dma_mapping_error(dma_addr))
  767. return -ENOMEM;
  768. memset(page, 0, off + count);
  769. memset(&vsp_cmd, 0, sizeof(vsp_cmd));
  770. vsp_cmd.cmd = 33;
  771. vsp_cmd.sub_data.kern.token = dma_addr;
  772. vsp_cmd.sub_data.kern.address_type = HvLpDma_AddressType_TceIndex;
  773. vsp_cmd.sub_data.kern.side = (u64)data;
  774. vsp_cmd.sub_data.kern.length = off + count;
  775. mb();
  776. rc = signal_vsp_instruction(&vsp_cmd);
  777. dma_unmap_single(iSeries_vio_dev, dma_addr, off + count,
  778. DMA_FROM_DEVICE);
  779. if (rc)
  780. return rc;
  781. if (vsp_cmd.result_code != 0)
  782. return -ENOMEM;
  783. p = page;
  784. len = 0;
  785. while (len < (off + count)) {
  786. if ((*p == '\0') || (*p == '\n')) {
  787. if (*p == '\0')
  788. *p = '\n';
  789. p++;
  790. len++;
  791. *eof = 1;
  792. break;
  793. }
  794. p++;
  795. len++;
  796. }
  797. if (len < off) {
  798. *eof = 1;
  799. len = 0;
  800. }
  801. return len;
  802. }
  803. #if 0
  804. static int mf_getVmlinuxChunk(char *buffer, int *size, int offset, u64 side)
  805. {
  806. struct vsp_cmd_data vsp_cmd;
  807. int rc;
  808. int len = *size;
  809. dma_addr_t dma_addr;
  810. dma_addr = dma_map_single(iSeries_vio_dev, buffer, len,
  811. DMA_FROM_DEVICE);
  812. memset(buffer, 0, len);
  813. memset(&vsp_cmd, 0, sizeof(vsp_cmd));
  814. vsp_cmd.cmd = 32;
  815. vsp_cmd.sub_data.kern.token = dma_addr;
  816. vsp_cmd.sub_data.kern.address_type = HvLpDma_AddressType_TceIndex;
  817. vsp_cmd.sub_data.kern.side = side;
  818. vsp_cmd.sub_data.kern.offset = offset;
  819. vsp_cmd.sub_data.kern.length = len;
  820. mb();
  821. rc = signal_vsp_instruction(&vsp_cmd);
  822. if (rc == 0) {
  823. if (vsp_cmd.result_code == 0)
  824. *size = vsp_cmd.sub_data.length_out;
  825. else
  826. rc = -ENOMEM;
  827. }
  828. dma_unmap_single(iSeries_vio_dev, dma_addr, len, DMA_FROM_DEVICE);
  829. return rc;
  830. }
  831. static int proc_mf_dump_vmlinux(char *page, char **start, off_t off,
  832. int count, int *eof, void *data)
  833. {
  834. int sizeToGet = count;
  835. if (!capable(CAP_SYS_ADMIN))
  836. return -EACCES;
  837. if (mf_getVmlinuxChunk(page, &sizeToGet, off, (u64)data) == 0) {
  838. if (sizeToGet != 0) {
  839. *start = page + off;
  840. return sizeToGet;
  841. }
  842. *eof = 1;
  843. return 0;
  844. }
  845. *eof = 1;
  846. return 0;
  847. }
  848. #endif
  849. static int proc_mf_dump_side(char *page, char **start, off_t off,
  850. int count, int *eof, void *data)
  851. {
  852. int len;
  853. char mf_current_side = ' ';
  854. struct vsp_cmd_data vsp_cmd;
  855. memset(&vsp_cmd, 0, sizeof(vsp_cmd));
  856. vsp_cmd.cmd = 2;
  857. vsp_cmd.sub_data.ipl_type = 0;
  858. mb();
  859. if (signal_vsp_instruction(&vsp_cmd) == 0) {
  860. if (vsp_cmd.result_code == 0) {
  861. switch (vsp_cmd.sub_data.ipl_type) {
  862. case 0: mf_current_side = 'A';
  863. break;
  864. case 1: mf_current_side = 'B';
  865. break;
  866. case 2: mf_current_side = 'C';
  867. break;
  868. default: mf_current_side = 'D';
  869. break;
  870. }
  871. }
  872. }
  873. len = sprintf(page, "%c\n", mf_current_side);
  874. if (len <= (off + count))
  875. *eof = 1;
  876. *start = page + off;
  877. len -= off;
  878. if (len > count)
  879. len = count;
  880. if (len < 0)
  881. len = 0;
  882. return len;
  883. }
  884. static int proc_mf_change_side(struct file *file, const char __user *buffer,
  885. unsigned long count, void *data)
  886. {
  887. char side;
  888. u64 newSide;
  889. struct vsp_cmd_data vsp_cmd;
  890. if (!capable(CAP_SYS_ADMIN))
  891. return -EACCES;
  892. if (count == 0)
  893. return 0;
  894. if (get_user(side, buffer))
  895. return -EFAULT;
  896. switch (side) {
  897. case 'A': newSide = 0;
  898. break;
  899. case 'B': newSide = 1;
  900. break;
  901. case 'C': newSide = 2;
  902. break;
  903. case 'D': newSide = 3;
  904. break;
  905. default:
  906. printk(KERN_ERR "mf_proc.c: proc_mf_change_side: invalid side\n");
  907. return -EINVAL;
  908. }
  909. memset(&vsp_cmd, 0, sizeof(vsp_cmd));
  910. vsp_cmd.sub_data.ipl_type = newSide;
  911. vsp_cmd.cmd = 10;
  912. (void)signal_vsp_instruction(&vsp_cmd);
  913. return count;
  914. }
  915. #if 0
  916. static void mf_getSrcHistory(char *buffer, int size)
  917. {
  918. struct IplTypeReturnStuff return_stuff;
  919. struct pending_event *ev = new_pending_event();
  920. int rc = 0;
  921. char *pages[4];
  922. pages[0] = kmalloc(4096, GFP_ATOMIC);
  923. pages[1] = kmalloc(4096, GFP_ATOMIC);
  924. pages[2] = kmalloc(4096, GFP_ATOMIC);
  925. pages[3] = kmalloc(4096, GFP_ATOMIC);
  926. if ((ev == NULL) || (pages[0] == NULL) || (pages[1] == NULL)
  927. || (pages[2] == NULL) || (pages[3] == NULL))
  928. return -ENOMEM;
  929. return_stuff.xType = 0;
  930. return_stuff.xRc = 0;
  931. return_stuff.xDone = 0;
  932. ev->event.hp_lp_event.xSubtype = 6;
  933. ev->event.hp_lp_event.x.xSubtypeData =
  934. subtype_data('M', 'F', 'V', 'I');
  935. ev->event.data.vsp_cmd.xEvent = &return_stuff;
  936. ev->event.data.vsp_cmd.cmd = 4;
  937. ev->event.data.vsp_cmd.lp_index = HvLpConfig_getLpIndex();
  938. ev->event.data.vsp_cmd.result_code = 0xFF;
  939. ev->event.data.vsp_cmd.reserved = 0;
  940. ev->event.data.vsp_cmd.sub_data.page[0] = iseries_hv_addr(pages[0]);
  941. ev->event.data.vsp_cmd.sub_data.page[1] = iseries_hv_addr(pages[1]);
  942. ev->event.data.vsp_cmd.sub_data.page[2] = iseries_hv_addr(pages[2]);
  943. ev->event.data.vsp_cmd.sub_data.page[3] = iseries_hv_addr(pages[3]);
  944. mb();
  945. if (signal_event(ev) != 0)
  946. return;
  947. while (return_stuff.xDone != 1)
  948. udelay(10);
  949. if (return_stuff.xRc == 0)
  950. memcpy(buffer, pages[0], size);
  951. kfree(pages[0]);
  952. kfree(pages[1]);
  953. kfree(pages[2]);
  954. kfree(pages[3]);
  955. }
  956. #endif
  957. static int proc_mf_dump_src(char *page, char **start, off_t off,
  958. int count, int *eof, void *data)
  959. {
  960. #if 0
  961. int len;
  962. mf_getSrcHistory(page, count);
  963. len = count;
  964. len -= off;
  965. if (len < count) {
  966. *eof = 1;
  967. if (len <= 0)
  968. return 0;
  969. } else
  970. len = count;
  971. *start = page + off;
  972. return len;
  973. #else
  974. return 0;
  975. #endif
  976. }
  977. static int proc_mf_change_src(struct file *file, const char __user *buffer,
  978. unsigned long count, void *data)
  979. {
  980. char stkbuf[10];
  981. if (!capable(CAP_SYS_ADMIN))
  982. return -EACCES;
  983. if ((count < 4) && (count != 1)) {
  984. printk(KERN_ERR "mf_proc: invalid src\n");
  985. return -EINVAL;
  986. }
  987. if (count > (sizeof(stkbuf) - 1))
  988. count = sizeof(stkbuf) - 1;
  989. if (copy_from_user(stkbuf, buffer, count))
  990. return -EFAULT;
  991. if ((count == 1) && (*stkbuf == '\0'))
  992. mf_clear_src();
  993. else
  994. mf_display_src(*(u32 *)stkbuf);
  995. return count;
  996. }
  997. static int proc_mf_change_cmdline(struct file *file, const char __user *buffer,
  998. unsigned long count, void *data)
  999. {
  1000. struct vsp_cmd_data vsp_cmd;
  1001. dma_addr_t dma_addr;
  1002. char *page;
  1003. int ret = -EACCES;
  1004. if (!capable(CAP_SYS_ADMIN))
  1005. goto out;
  1006. dma_addr = 0;
  1007. page = dma_alloc_coherent(iSeries_vio_dev, count, &dma_addr,
  1008. GFP_ATOMIC);
  1009. ret = -ENOMEM;
  1010. if (page == NULL)
  1011. goto out;
  1012. ret = -EFAULT;
  1013. if (copy_from_user(page, buffer, count))
  1014. goto out_free;
  1015. memset(&vsp_cmd, 0, sizeof(vsp_cmd));
  1016. vsp_cmd.cmd = 31;
  1017. vsp_cmd.sub_data.kern.token = dma_addr;
  1018. vsp_cmd.sub_data.kern.address_type = HvLpDma_AddressType_TceIndex;
  1019. vsp_cmd.sub_data.kern.side = (u64)data;
  1020. vsp_cmd.sub_data.kern.length = count;
  1021. mb();
  1022. (void)signal_vsp_instruction(&vsp_cmd);
  1023. ret = count;
  1024. out_free:
  1025. dma_free_coherent(iSeries_vio_dev, count, page, dma_addr);
  1026. out:
  1027. return ret;
  1028. }
  1029. static ssize_t proc_mf_change_vmlinux(struct file *file,
  1030. const char __user *buf,
  1031. size_t count, loff_t *ppos)
  1032. {
  1033. struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode);
  1034. ssize_t rc;
  1035. dma_addr_t dma_addr;
  1036. char *page;
  1037. struct vsp_cmd_data vsp_cmd;
  1038. rc = -EACCES;
  1039. if (!capable(CAP_SYS_ADMIN))
  1040. goto out;
  1041. dma_addr = 0;
  1042. page = dma_alloc_coherent(iSeries_vio_dev, count, &dma_addr,
  1043. GFP_ATOMIC);
  1044. rc = -ENOMEM;
  1045. if (page == NULL) {
  1046. printk(KERN_ERR "mf.c: couldn't allocate memory to set vmlinux chunk\n");
  1047. goto out;
  1048. }
  1049. rc = -EFAULT;
  1050. if (copy_from_user(page, buf, count))
  1051. goto out_free;
  1052. memset(&vsp_cmd, 0, sizeof(vsp_cmd));
  1053. vsp_cmd.cmd = 30;
  1054. vsp_cmd.sub_data.kern.token = dma_addr;
  1055. vsp_cmd.sub_data.kern.address_type = HvLpDma_AddressType_TceIndex;
  1056. vsp_cmd.sub_data.kern.side = (u64)dp->data;
  1057. vsp_cmd.sub_data.kern.offset = *ppos;
  1058. vsp_cmd.sub_data.kern.length = count;
  1059. mb();
  1060. rc = signal_vsp_instruction(&vsp_cmd);
  1061. if (rc)
  1062. goto out_free;
  1063. rc = -ENOMEM;
  1064. if (vsp_cmd.result_code != 0)
  1065. goto out_free;
  1066. *ppos += count;
  1067. rc = count;
  1068. out_free:
  1069. dma_free_coherent(iSeries_vio_dev, count, page, dma_addr);
  1070. out:
  1071. return rc;
  1072. }
  1073. static struct file_operations proc_vmlinux_operations = {
  1074. .write = proc_mf_change_vmlinux,
  1075. };
  1076. static int __init mf_proc_init(void)
  1077. {
  1078. struct proc_dir_entry *mf_proc_root;
  1079. struct proc_dir_entry *ent;
  1080. struct proc_dir_entry *mf;
  1081. char name[2];
  1082. int i;
  1083. mf_proc_root = proc_mkdir("iSeries/mf", NULL);
  1084. if (!mf_proc_root)
  1085. return 1;
  1086. name[1] = '\0';
  1087. for (i = 0; i < 4; i++) {
  1088. name[0] = 'A' + i;
  1089. mf = proc_mkdir(name, mf_proc_root);
  1090. if (!mf)
  1091. return 1;
  1092. ent = create_proc_entry("cmdline", S_IFREG|S_IRUSR|S_IWUSR, mf);
  1093. if (!ent)
  1094. return 1;
  1095. ent->nlink = 1;
  1096. ent->data = (void *)(long)i;
  1097. ent->read_proc = proc_mf_dump_cmdline;
  1098. ent->write_proc = proc_mf_change_cmdline;
  1099. if (i == 3) /* no vmlinux entry for 'D' */
  1100. continue;
  1101. ent = create_proc_entry("vmlinux", S_IFREG|S_IWUSR, mf);
  1102. if (!ent)
  1103. return 1;
  1104. ent->nlink = 1;
  1105. ent->data = (void *)(long)i;
  1106. ent->proc_fops = &proc_vmlinux_operations;
  1107. }
  1108. ent = create_proc_entry("side", S_IFREG|S_IRUSR|S_IWUSR, mf_proc_root);
  1109. if (!ent)
  1110. return 1;
  1111. ent->nlink = 1;
  1112. ent->data = (void *)0;
  1113. ent->read_proc = proc_mf_dump_side;
  1114. ent->write_proc = proc_mf_change_side;
  1115. ent = create_proc_entry("src", S_IFREG|S_IRUSR|S_IWUSR, mf_proc_root);
  1116. if (!ent)
  1117. return 1;
  1118. ent->nlink = 1;
  1119. ent->data = (void *)0;
  1120. ent->read_proc = proc_mf_dump_src;
  1121. ent->write_proc = proc_mf_change_src;
  1122. return 0;
  1123. }
  1124. __initcall(mf_proc_init);
  1125. #endif /* CONFIG_PROC_FS */
  1126. /*
  1127. * Get the RTC from the virtual service processor
  1128. * This requires flowing LpEvents to the primary partition
  1129. */
  1130. void iSeries_get_rtc_time(struct rtc_time *rtc_tm)
  1131. {
  1132. if (piranha_simulator)
  1133. return;
  1134. mf_get_rtc(rtc_tm);
  1135. rtc_tm->tm_mon--;
  1136. }
  1137. /*
  1138. * Set the RTC in the virtual service processor
  1139. * This requires flowing LpEvents to the primary partition
  1140. */
  1141. int iSeries_set_rtc_time(struct rtc_time *tm)
  1142. {
  1143. mf_set_rtc(tm);
  1144. return 0;
  1145. }
  1146. unsigned long iSeries_get_boot_time(void)
  1147. {
  1148. struct rtc_time tm;
  1149. if (piranha_simulator)
  1150. return 0;
  1151. mf_get_boot_rtc(&tm);
  1152. return mktime(tm.tm_year + 1900, tm.tm_mon, tm.tm_mday,
  1153. tm.tm_hour, tm.tm_min, tm.tm_sec);
  1154. }