mf.c 31 KB

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