mf.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321
  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->xFlags.xValid = 1;
  229. hev->xFlags.xAckType = HvLpEvent_AckType_ImmediateAck;
  230. hev->xFlags.xAckInd = HvLpEvent_AckInd_DoAck;
  231. hev->xFlags.xFunction = HvLpEvent_Function_Int;
  232. hev->xType = HvLpEvent_Type_MachineFac;
  233. hev->xSourceLp = HvLpConfig_getLpIndex();
  234. hev->xTargetLp = primary_lp;
  235. hev->xSizeMinus1 = sizeof(ev->event) - 1;
  236. hev->xRc = HvLpEvent_Rc_Good;
  237. hev->xSourceInstanceId = HvCallEvent_getSourceLpInstanceId(primary_lp,
  238. HvLpEvent_Type_MachineFac);
  239. hev->xTargetInstanceId = HvCallEvent_getTargetLpInstanceId(primary_lp,
  240. HvLpEvent_Type_MachineFac);
  241. return ev;
  242. }
  243. static int 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_proc(1, 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, struct pt_regs *regs)
  465. {
  466. if ((event != NULL) && (event->xType == HvLpEvent_Type_MachineFac)) {
  467. switch(event->xFlags.xFunction) {
  468. case HvLpEvent_Function_Ack:
  469. handle_ack((struct io_mf_lp_event *)event);
  470. break;
  471. case HvLpEvent_Function_Int:
  472. handle_int((struct io_mf_lp_event *)event);
  473. break;
  474. default:
  475. printk(KERN_ERR "mf.c: non ack/int event received\n");
  476. break;
  477. }
  478. } else
  479. printk(KERN_ERR "mf.c: alien event received\n");
  480. }
  481. /*
  482. * Global kernel interface to allocate and seed events into the
  483. * Hypervisor.
  484. */
  485. void mf_allocate_lp_events(HvLpIndex target_lp, HvLpEvent_Type type,
  486. unsigned size, unsigned count, MFCompleteHandler hdlr,
  487. void *user_token)
  488. {
  489. struct pending_event *ev = new_pending_event();
  490. int rc;
  491. if (ev == NULL) {
  492. rc = -ENOMEM;
  493. } else {
  494. ev->event.hp_lp_event.xSubtype = 4;
  495. ev->event.hp_lp_event.xCorrelationToken = (u64)user_token;
  496. ev->event.hp_lp_event.x.xSubtypeData =
  497. subtype_data('M', 'F', 'M', 'A');
  498. ev->event.data.alloc.target_lp = target_lp;
  499. ev->event.data.alloc.type = type;
  500. ev->event.data.alloc.size = size;
  501. ev->event.data.alloc.count = count;
  502. ev->hdlr = hdlr;
  503. rc = signal_event(ev);
  504. }
  505. if ((rc != 0) && (hdlr != NULL))
  506. (*hdlr)(user_token, rc);
  507. }
  508. EXPORT_SYMBOL(mf_allocate_lp_events);
  509. /*
  510. * Global kernel interface to unseed and deallocate events already in
  511. * Hypervisor.
  512. */
  513. void mf_deallocate_lp_events(HvLpIndex target_lp, HvLpEvent_Type type,
  514. unsigned count, MFCompleteHandler hdlr, void *user_token)
  515. {
  516. struct pending_event *ev = new_pending_event();
  517. int rc;
  518. if (ev == NULL)
  519. rc = -ENOMEM;
  520. else {
  521. ev->event.hp_lp_event.xSubtype = 5;
  522. ev->event.hp_lp_event.xCorrelationToken = (u64)user_token;
  523. ev->event.hp_lp_event.x.xSubtypeData =
  524. subtype_data('M', 'F', 'M', 'D');
  525. ev->event.data.alloc.target_lp = target_lp;
  526. ev->event.data.alloc.type = type;
  527. ev->event.data.alloc.count = count;
  528. ev->hdlr = hdlr;
  529. rc = signal_event(ev);
  530. }
  531. if ((rc != 0) && (hdlr != NULL))
  532. (*hdlr)(user_token, rc);
  533. }
  534. EXPORT_SYMBOL(mf_deallocate_lp_events);
  535. /*
  536. * Global kernel interface to tell the VSP object in the primary
  537. * partition to power this partition off.
  538. */
  539. void mf_power_off(void)
  540. {
  541. printk(KERN_INFO "mf.c: Down it goes...\n");
  542. signal_ce_msg_simple(0x4d, NULL);
  543. for (;;)
  544. ;
  545. }
  546. /*
  547. * Global kernel interface to tell the VSP object in the primary
  548. * partition to reboot this partition.
  549. */
  550. void mf_reboot(void)
  551. {
  552. printk(KERN_INFO "mf.c: Preparing to bounce...\n");
  553. signal_ce_msg_simple(0x4e, NULL);
  554. for (;;)
  555. ;
  556. }
  557. /*
  558. * Display a single word SRC onto the VSP control panel.
  559. */
  560. void mf_display_src(u32 word)
  561. {
  562. u8 ce[12];
  563. memset(ce, 0, sizeof(ce));
  564. ce[3] = 0x4a;
  565. ce[7] = 0x01;
  566. ce[8] = word >> 24;
  567. ce[9] = word >> 16;
  568. ce[10] = word >> 8;
  569. ce[11] = word;
  570. signal_ce_msg(ce, NULL);
  571. }
  572. /*
  573. * Display a single word SRC of the form "PROGXXXX" on the VSP control panel.
  574. */
  575. void mf_display_progress(u16 value)
  576. {
  577. u8 ce[12];
  578. u8 src[72];
  579. memcpy(ce, "\x00\x00\x04\x4A\x00\x00\x00\x48\x00\x00\x00\x00", 12);
  580. memcpy(src, "\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00"
  581. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  582. "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
  583. "\x00\x00\x00\x00PROGxxxx ",
  584. 72);
  585. src[6] = value >> 8;
  586. src[7] = value & 255;
  587. src[44] = "0123456789ABCDEF"[(value >> 12) & 15];
  588. src[45] = "0123456789ABCDEF"[(value >> 8) & 15];
  589. src[46] = "0123456789ABCDEF"[(value >> 4) & 15];
  590. src[47] = "0123456789ABCDEF"[value & 15];
  591. dma_and_signal_ce_msg(ce, NULL, src, sizeof(src), 9 * 64 * 1024);
  592. }
  593. /*
  594. * Clear the VSP control panel. Used to "erase" an SRC that was
  595. * previously displayed.
  596. */
  597. void mf_clear_src(void)
  598. {
  599. signal_ce_msg_simple(0x4b, NULL);
  600. }
  601. /*
  602. * Initialization code here.
  603. */
  604. void mf_init(void)
  605. {
  606. int i;
  607. /* initialize */
  608. spin_lock_init(&pending_event_spinlock);
  609. for (i = 0;
  610. i < sizeof(pending_event_prealloc) / sizeof(*pending_event_prealloc);
  611. ++i)
  612. free_pending_event(&pending_event_prealloc[i]);
  613. HvLpEvent_registerHandler(HvLpEvent_Type_MachineFac, &hv_handler);
  614. /* virtual continue ack */
  615. signal_ce_msg_simple(0x57, NULL);
  616. /* initialization complete */
  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 rtc_set_tm(int rc, u8 *ce_msg, struct rtc_time *tm)
  633. {
  634. tm->tm_wday = 0;
  635. tm->tm_yday = 0;
  636. tm->tm_isdst = 0;
  637. if (rc) {
  638. tm->tm_sec = 0;
  639. tm->tm_min = 0;
  640. tm->tm_hour = 0;
  641. tm->tm_mday = 15;
  642. tm->tm_mon = 5;
  643. tm->tm_year = 52;
  644. return rc;
  645. }
  646. if ((ce_msg[2] == 0xa9) ||
  647. (ce_msg[2] == 0xaf)) {
  648. /* TOD clock is not set */
  649. tm->tm_sec = 1;
  650. tm->tm_min = 1;
  651. tm->tm_hour = 1;
  652. tm->tm_mday = 10;
  653. tm->tm_mon = 8;
  654. tm->tm_year = 71;
  655. mf_set_rtc(tm);
  656. }
  657. {
  658. u8 year = ce_msg[5];
  659. u8 sec = ce_msg[6];
  660. u8 min = ce_msg[7];
  661. u8 hour = ce_msg[8];
  662. u8 day = ce_msg[10];
  663. u8 mon = ce_msg[11];
  664. BCD_TO_BIN(sec);
  665. BCD_TO_BIN(min);
  666. BCD_TO_BIN(hour);
  667. BCD_TO_BIN(day);
  668. BCD_TO_BIN(mon);
  669. BCD_TO_BIN(year);
  670. if (year <= 69)
  671. year += 100;
  672. tm->tm_sec = sec;
  673. tm->tm_min = min;
  674. tm->tm_hour = hour;
  675. tm->tm_mday = day;
  676. tm->tm_mon = mon;
  677. tm->tm_year = year;
  678. }
  679. return 0;
  680. }
  681. int mf_get_rtc(struct rtc_time *tm)
  682. {
  683. struct ce_msg_comp_data ce_complete;
  684. struct rtc_time_data rtc_data;
  685. int rc;
  686. memset(&ce_complete, 0, sizeof(ce_complete));
  687. memset(&rtc_data, 0, sizeof(rtc_data));
  688. init_completion(&rtc_data.com);
  689. ce_complete.handler = &get_rtc_time_complete;
  690. ce_complete.token = &rtc_data;
  691. rc = signal_ce_msg_simple(0x40, &ce_complete);
  692. if (rc)
  693. return rc;
  694. wait_for_completion(&rtc_data.com);
  695. return rtc_set_tm(rtc_data.rc, rtc_data.ce_msg.ce_msg, tm);
  696. }
  697. struct boot_rtc_time_data {
  698. int busy;
  699. struct ce_msg_data ce_msg;
  700. int rc;
  701. };
  702. static void get_boot_rtc_time_complete(void *token, struct ce_msg_data *ce_msg)
  703. {
  704. struct boot_rtc_time_data *rtc = token;
  705. memcpy(&rtc->ce_msg, ce_msg, sizeof(rtc->ce_msg));
  706. rtc->rc = 0;
  707. rtc->busy = 0;
  708. }
  709. int mf_get_boot_rtc(struct rtc_time *tm)
  710. {
  711. struct ce_msg_comp_data ce_complete;
  712. struct boot_rtc_time_data rtc_data;
  713. int rc;
  714. memset(&ce_complete, 0, sizeof(ce_complete));
  715. memset(&rtc_data, 0, sizeof(rtc_data));
  716. rtc_data.busy = 1;
  717. ce_complete.handler = &get_boot_rtc_time_complete;
  718. ce_complete.token = &rtc_data;
  719. rc = signal_ce_msg_simple(0x40, &ce_complete);
  720. if (rc)
  721. return rc;
  722. /* We need to poll here as we are not yet taking interrupts */
  723. while (rtc_data.busy) {
  724. if (hvlpevent_is_pending())
  725. process_hvlpevents(NULL);
  726. }
  727. return rtc_set_tm(rtc_data.rc, rtc_data.ce_msg.ce_msg, tm);
  728. }
  729. int mf_set_rtc(struct rtc_time *tm)
  730. {
  731. char ce_time[12];
  732. u8 day, mon, hour, min, sec, y1, y2;
  733. unsigned year;
  734. year = 1900 + tm->tm_year;
  735. y1 = year / 100;
  736. y2 = year % 100;
  737. sec = tm->tm_sec;
  738. min = tm->tm_min;
  739. hour = tm->tm_hour;
  740. day = tm->tm_mday;
  741. mon = tm->tm_mon + 1;
  742. BIN_TO_BCD(sec);
  743. BIN_TO_BCD(min);
  744. BIN_TO_BCD(hour);
  745. BIN_TO_BCD(mon);
  746. BIN_TO_BCD(day);
  747. BIN_TO_BCD(y1);
  748. BIN_TO_BCD(y2);
  749. memset(ce_time, 0, sizeof(ce_time));
  750. ce_time[3] = 0x41;
  751. ce_time[4] = y1;
  752. ce_time[5] = y2;
  753. ce_time[6] = sec;
  754. ce_time[7] = min;
  755. ce_time[8] = hour;
  756. ce_time[10] = day;
  757. ce_time[11] = mon;
  758. return signal_ce_msg(ce_time, NULL);
  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 = dma_map_single(iSeries_vio_dev, page, off + count,
  775. DMA_FROM_DEVICE);
  776. if (dma_mapping_error(dma_addr))
  777. return -ENOMEM;
  778. memset(page, 0, off + count);
  779. memset(&vsp_cmd, 0, sizeof(vsp_cmd));
  780. vsp_cmd.cmd = 33;
  781. vsp_cmd.sub_data.kern.token = dma_addr;
  782. vsp_cmd.sub_data.kern.address_type = HvLpDma_AddressType_TceIndex;
  783. vsp_cmd.sub_data.kern.side = (u64)data;
  784. vsp_cmd.sub_data.kern.length = off + count;
  785. mb();
  786. rc = signal_vsp_instruction(&vsp_cmd);
  787. dma_unmap_single(iSeries_vio_dev, dma_addr, off + count,
  788. DMA_FROM_DEVICE);
  789. if (rc)
  790. return rc;
  791. if (vsp_cmd.result_code != 0)
  792. return -ENOMEM;
  793. p = page;
  794. len = 0;
  795. while (len < (off + count)) {
  796. if ((*p == '\0') || (*p == '\n')) {
  797. if (*p == '\0')
  798. *p = '\n';
  799. p++;
  800. len++;
  801. *eof = 1;
  802. break;
  803. }
  804. p++;
  805. len++;
  806. }
  807. if (len < off) {
  808. *eof = 1;
  809. len = 0;
  810. }
  811. return len;
  812. }
  813. #if 0
  814. static int mf_getVmlinuxChunk(char *buffer, int *size, int offset, u64 side)
  815. {
  816. struct vsp_cmd_data vsp_cmd;
  817. int rc;
  818. int len = *size;
  819. dma_addr_t dma_addr;
  820. dma_addr = dma_map_single(iSeries_vio_dev, buffer, len,
  821. DMA_FROM_DEVICE);
  822. memset(buffer, 0, len);
  823. memset(&vsp_cmd, 0, sizeof(vsp_cmd));
  824. vsp_cmd.cmd = 32;
  825. vsp_cmd.sub_data.kern.token = dma_addr;
  826. vsp_cmd.sub_data.kern.address_type = HvLpDma_AddressType_TceIndex;
  827. vsp_cmd.sub_data.kern.side = side;
  828. vsp_cmd.sub_data.kern.offset = offset;
  829. vsp_cmd.sub_data.kern.length = len;
  830. mb();
  831. rc = signal_vsp_instruction(&vsp_cmd);
  832. if (rc == 0) {
  833. if (vsp_cmd.result_code == 0)
  834. *size = vsp_cmd.sub_data.length_out;
  835. else
  836. rc = -ENOMEM;
  837. }
  838. dma_unmap_single(iSeries_vio_dev, dma_addr, len, DMA_FROM_DEVICE);
  839. return rc;
  840. }
  841. static int proc_mf_dump_vmlinux(char *page, char **start, off_t off,
  842. int count, int *eof, void *data)
  843. {
  844. int sizeToGet = count;
  845. if (!capable(CAP_SYS_ADMIN))
  846. return -EACCES;
  847. if (mf_getVmlinuxChunk(page, &sizeToGet, off, (u64)data) == 0) {
  848. if (sizeToGet != 0) {
  849. *start = page + off;
  850. return sizeToGet;
  851. }
  852. *eof = 1;
  853. return 0;
  854. }
  855. *eof = 1;
  856. return 0;
  857. }
  858. #endif
  859. static int proc_mf_dump_side(char *page, char **start, off_t off,
  860. int count, int *eof, void *data)
  861. {
  862. int len;
  863. char mf_current_side = ' ';
  864. struct vsp_cmd_data vsp_cmd;
  865. memset(&vsp_cmd, 0, sizeof(vsp_cmd));
  866. vsp_cmd.cmd = 2;
  867. vsp_cmd.sub_data.ipl_type = 0;
  868. mb();
  869. if (signal_vsp_instruction(&vsp_cmd) == 0) {
  870. if (vsp_cmd.result_code == 0) {
  871. switch (vsp_cmd.sub_data.ipl_type) {
  872. case 0: mf_current_side = 'A';
  873. break;
  874. case 1: mf_current_side = 'B';
  875. break;
  876. case 2: mf_current_side = 'C';
  877. break;
  878. default: mf_current_side = 'D';
  879. break;
  880. }
  881. }
  882. }
  883. len = sprintf(page, "%c\n", mf_current_side);
  884. if (len <= (off + count))
  885. *eof = 1;
  886. *start = page + off;
  887. len -= off;
  888. if (len > count)
  889. len = count;
  890. if (len < 0)
  891. len = 0;
  892. return len;
  893. }
  894. static int proc_mf_change_side(struct file *file, const char __user *buffer,
  895. unsigned long count, void *data)
  896. {
  897. char side;
  898. u64 newSide;
  899. struct vsp_cmd_data vsp_cmd;
  900. if (!capable(CAP_SYS_ADMIN))
  901. return -EACCES;
  902. if (count == 0)
  903. return 0;
  904. if (get_user(side, buffer))
  905. return -EFAULT;
  906. switch (side) {
  907. case 'A': newSide = 0;
  908. break;
  909. case 'B': newSide = 1;
  910. break;
  911. case 'C': newSide = 2;
  912. break;
  913. case 'D': newSide = 3;
  914. break;
  915. default:
  916. printk(KERN_ERR "mf_proc.c: proc_mf_change_side: invalid side\n");
  917. return -EINVAL;
  918. }
  919. memset(&vsp_cmd, 0, sizeof(vsp_cmd));
  920. vsp_cmd.sub_data.ipl_type = newSide;
  921. vsp_cmd.cmd = 10;
  922. (void)signal_vsp_instruction(&vsp_cmd);
  923. return count;
  924. }
  925. #if 0
  926. static void mf_getSrcHistory(char *buffer, int size)
  927. {
  928. struct IplTypeReturnStuff return_stuff;
  929. struct pending_event *ev = new_pending_event();
  930. int rc = 0;
  931. char *pages[4];
  932. pages[0] = kmalloc(4096, GFP_ATOMIC);
  933. pages[1] = kmalloc(4096, GFP_ATOMIC);
  934. pages[2] = kmalloc(4096, GFP_ATOMIC);
  935. pages[3] = kmalloc(4096, GFP_ATOMIC);
  936. if ((ev == NULL) || (pages[0] == NULL) || (pages[1] == NULL)
  937. || (pages[2] == NULL) || (pages[3] == NULL))
  938. return -ENOMEM;
  939. return_stuff.xType = 0;
  940. return_stuff.xRc = 0;
  941. return_stuff.xDone = 0;
  942. ev->event.hp_lp_event.xSubtype = 6;
  943. ev->event.hp_lp_event.x.xSubtypeData =
  944. subtype_data('M', 'F', 'V', 'I');
  945. ev->event.data.vsp_cmd.xEvent = &return_stuff;
  946. ev->event.data.vsp_cmd.cmd = 4;
  947. ev->event.data.vsp_cmd.lp_index = HvLpConfig_getLpIndex();
  948. ev->event.data.vsp_cmd.result_code = 0xFF;
  949. ev->event.data.vsp_cmd.reserved = 0;
  950. ev->event.data.vsp_cmd.sub_data.page[0] = iseries_hv_addr(pages[0]);
  951. ev->event.data.vsp_cmd.sub_data.page[1] = iseries_hv_addr(pages[1]);
  952. ev->event.data.vsp_cmd.sub_data.page[2] = iseries_hv_addr(pages[2]);
  953. ev->event.data.vsp_cmd.sub_data.page[3] = iseries_hv_addr(pages[3]);
  954. mb();
  955. if (signal_event(ev) != 0)
  956. return;
  957. while (return_stuff.xDone != 1)
  958. udelay(10);
  959. if (return_stuff.xRc == 0)
  960. memcpy(buffer, pages[0], size);
  961. kfree(pages[0]);
  962. kfree(pages[1]);
  963. kfree(pages[2]);
  964. kfree(pages[3]);
  965. }
  966. #endif
  967. static int proc_mf_dump_src(char *page, char **start, off_t off,
  968. int count, int *eof, void *data)
  969. {
  970. #if 0
  971. int len;
  972. mf_getSrcHistory(page, count);
  973. len = count;
  974. len -= off;
  975. if (len < count) {
  976. *eof = 1;
  977. if (len <= 0)
  978. return 0;
  979. } else
  980. len = count;
  981. *start = page + off;
  982. return len;
  983. #else
  984. return 0;
  985. #endif
  986. }
  987. static int proc_mf_change_src(struct file *file, const char __user *buffer,
  988. unsigned long count, void *data)
  989. {
  990. char stkbuf[10];
  991. if (!capable(CAP_SYS_ADMIN))
  992. return -EACCES;
  993. if ((count < 4) && (count != 1)) {
  994. printk(KERN_ERR "mf_proc: invalid src\n");
  995. return -EINVAL;
  996. }
  997. if (count > (sizeof(stkbuf) - 1))
  998. count = sizeof(stkbuf) - 1;
  999. if (copy_from_user(stkbuf, buffer, count))
  1000. return -EFAULT;
  1001. if ((count == 1) && (*stkbuf == '\0'))
  1002. mf_clear_src();
  1003. else
  1004. mf_display_src(*(u32 *)stkbuf);
  1005. return count;
  1006. }
  1007. static int proc_mf_change_cmdline(struct file *file, const char __user *buffer,
  1008. unsigned long count, void *data)
  1009. {
  1010. struct vsp_cmd_data vsp_cmd;
  1011. dma_addr_t dma_addr;
  1012. char *page;
  1013. int ret = -EACCES;
  1014. if (!capable(CAP_SYS_ADMIN))
  1015. goto out;
  1016. dma_addr = 0;
  1017. page = dma_alloc_coherent(iSeries_vio_dev, count, &dma_addr,
  1018. GFP_ATOMIC);
  1019. ret = -ENOMEM;
  1020. if (page == NULL)
  1021. goto out;
  1022. ret = -EFAULT;
  1023. if (copy_from_user(page, buffer, count))
  1024. goto out_free;
  1025. memset(&vsp_cmd, 0, sizeof(vsp_cmd));
  1026. vsp_cmd.cmd = 31;
  1027. vsp_cmd.sub_data.kern.token = dma_addr;
  1028. vsp_cmd.sub_data.kern.address_type = HvLpDma_AddressType_TceIndex;
  1029. vsp_cmd.sub_data.kern.side = (u64)data;
  1030. vsp_cmd.sub_data.kern.length = count;
  1031. mb();
  1032. (void)signal_vsp_instruction(&vsp_cmd);
  1033. ret = count;
  1034. out_free:
  1035. dma_free_coherent(iSeries_vio_dev, count, page, dma_addr);
  1036. out:
  1037. return ret;
  1038. }
  1039. static ssize_t proc_mf_change_vmlinux(struct file *file,
  1040. const char __user *buf,
  1041. size_t count, loff_t *ppos)
  1042. {
  1043. struct proc_dir_entry *dp = PDE(file->f_dentry->d_inode);
  1044. ssize_t rc;
  1045. dma_addr_t dma_addr;
  1046. char *page;
  1047. struct vsp_cmd_data vsp_cmd;
  1048. rc = -EACCES;
  1049. if (!capable(CAP_SYS_ADMIN))
  1050. goto out;
  1051. dma_addr = 0;
  1052. page = dma_alloc_coherent(iSeries_vio_dev, count, &dma_addr,
  1053. GFP_ATOMIC);
  1054. rc = -ENOMEM;
  1055. if (page == NULL) {
  1056. printk(KERN_ERR "mf.c: couldn't allocate memory to set vmlinux chunk\n");
  1057. goto out;
  1058. }
  1059. rc = -EFAULT;
  1060. if (copy_from_user(page, buf, count))
  1061. goto out_free;
  1062. memset(&vsp_cmd, 0, sizeof(vsp_cmd));
  1063. vsp_cmd.cmd = 30;
  1064. vsp_cmd.sub_data.kern.token = dma_addr;
  1065. vsp_cmd.sub_data.kern.address_type = HvLpDma_AddressType_TceIndex;
  1066. vsp_cmd.sub_data.kern.side = (u64)dp->data;
  1067. vsp_cmd.sub_data.kern.offset = *ppos;
  1068. vsp_cmd.sub_data.kern.length = count;
  1069. mb();
  1070. rc = signal_vsp_instruction(&vsp_cmd);
  1071. if (rc)
  1072. goto out_free;
  1073. rc = -ENOMEM;
  1074. if (vsp_cmd.result_code != 0)
  1075. goto out_free;
  1076. *ppos += count;
  1077. rc = count;
  1078. out_free:
  1079. dma_free_coherent(iSeries_vio_dev, count, page, dma_addr);
  1080. out:
  1081. return rc;
  1082. }
  1083. static struct file_operations proc_vmlinux_operations = {
  1084. .write = proc_mf_change_vmlinux,
  1085. };
  1086. static int __init mf_proc_init(void)
  1087. {
  1088. struct proc_dir_entry *mf_proc_root;
  1089. struct proc_dir_entry *ent;
  1090. struct proc_dir_entry *mf;
  1091. char name[2];
  1092. int i;
  1093. mf_proc_root = proc_mkdir("iSeries/mf", NULL);
  1094. if (!mf_proc_root)
  1095. return 1;
  1096. name[1] = '\0';
  1097. for (i = 0; i < 4; i++) {
  1098. name[0] = 'A' + i;
  1099. mf = proc_mkdir(name, mf_proc_root);
  1100. if (!mf)
  1101. return 1;
  1102. ent = create_proc_entry("cmdline", S_IFREG|S_IRUSR|S_IWUSR, mf);
  1103. if (!ent)
  1104. return 1;
  1105. ent->nlink = 1;
  1106. ent->data = (void *)(long)i;
  1107. ent->read_proc = proc_mf_dump_cmdline;
  1108. ent->write_proc = proc_mf_change_cmdline;
  1109. if (i == 3) /* no vmlinux entry for 'D' */
  1110. continue;
  1111. ent = create_proc_entry("vmlinux", S_IFREG|S_IWUSR, mf);
  1112. if (!ent)
  1113. return 1;
  1114. ent->nlink = 1;
  1115. ent->data = (void *)(long)i;
  1116. ent->proc_fops = &proc_vmlinux_operations;
  1117. }
  1118. ent = create_proc_entry("side", S_IFREG|S_IRUSR|S_IWUSR, mf_proc_root);
  1119. if (!ent)
  1120. return 1;
  1121. ent->nlink = 1;
  1122. ent->data = (void *)0;
  1123. ent->read_proc = proc_mf_dump_side;
  1124. ent->write_proc = proc_mf_change_side;
  1125. ent = create_proc_entry("src", S_IFREG|S_IRUSR|S_IWUSR, mf_proc_root);
  1126. if (!ent)
  1127. return 1;
  1128. ent->nlink = 1;
  1129. ent->data = (void *)0;
  1130. ent->read_proc = proc_mf_dump_src;
  1131. ent->write_proc = proc_mf_change_src;
  1132. return 0;
  1133. }
  1134. __initcall(mf_proc_init);
  1135. #endif /* CONFIG_PROC_FS */
  1136. /*
  1137. * Get the RTC from the virtual service processor
  1138. * This requires flowing LpEvents to the primary partition
  1139. */
  1140. void iSeries_get_rtc_time(struct rtc_time *rtc_tm)
  1141. {
  1142. if (piranha_simulator)
  1143. return;
  1144. mf_get_rtc(rtc_tm);
  1145. rtc_tm->tm_mon--;
  1146. }
  1147. /*
  1148. * Set the RTC in the virtual service processor
  1149. * This requires flowing LpEvents to the primary partition
  1150. */
  1151. int iSeries_set_rtc_time(struct rtc_time *tm)
  1152. {
  1153. mf_set_rtc(tm);
  1154. return 0;
  1155. }
  1156. unsigned long iSeries_get_boot_time(void)
  1157. {
  1158. struct rtc_time tm;
  1159. if (piranha_simulator)
  1160. return 0;
  1161. mf_get_boot_rtc(&tm);
  1162. return mktime(tm.tm_year + 1900, tm.tm_mon, tm.tm_mday,
  1163. tm.tm_hour, tm.tm_min, tm.tm_sec);
  1164. }