mf.c 31 KB

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