mf.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333
  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 mf_cmdline_proc_show(struct seq_file *m, void *v)
  762. {
  763. char *page, *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. page = kmalloc(256, GFP_KERNEL);
  769. if (!page)
  770. return -ENOMEM;
  771. dma_addr = iseries_hv_map(page, 256, DMA_FROM_DEVICE);
  772. if (dma_addr == DMA_ERROR_CODE) {
  773. kfree(page);
  774. return -ENOMEM;
  775. }
  776. memset(page, 0, 256);
  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)m->private;
  782. vsp_cmd.sub_data.kern.length = 256;
  783. mb();
  784. rc = signal_vsp_instruction(&vsp_cmd);
  785. iseries_hv_unmap(dma_addr, 256, DMA_FROM_DEVICE);
  786. if (rc) {
  787. kfree(page);
  788. return rc;
  789. }
  790. if (vsp_cmd.result_code != 0) {
  791. kfree(page);
  792. return -ENOMEM;
  793. }
  794. p = page;
  795. while (p - page < 256) {
  796. if (*p == '\0' || *p == '\n') {
  797. *p = '\n';
  798. break;
  799. }
  800. p++;
  801. }
  802. seq_write(m, page, p - page);
  803. kfree(page);
  804. return 0;
  805. }
  806. static int mf_cmdline_proc_open(struct inode *inode, struct file *file)
  807. {
  808. return single_open(file, mf_cmdline_proc_show, PDE(inode)->data);
  809. }
  810. #if 0
  811. static int mf_getVmlinuxChunk(char *buffer, int *size, int offset, u64 side)
  812. {
  813. struct vsp_cmd_data vsp_cmd;
  814. int rc;
  815. int len = *size;
  816. dma_addr_t dma_addr;
  817. dma_addr = iseries_hv_map(buffer, len, DMA_FROM_DEVICE);
  818. memset(buffer, 0, len);
  819. memset(&vsp_cmd, 0, sizeof(vsp_cmd));
  820. vsp_cmd.cmd = 32;
  821. vsp_cmd.sub_data.kern.token = dma_addr;
  822. vsp_cmd.sub_data.kern.address_type = HvLpDma_AddressType_TceIndex;
  823. vsp_cmd.sub_data.kern.side = side;
  824. vsp_cmd.sub_data.kern.offset = offset;
  825. vsp_cmd.sub_data.kern.length = len;
  826. mb();
  827. rc = signal_vsp_instruction(&vsp_cmd);
  828. if (rc == 0) {
  829. if (vsp_cmd.result_code == 0)
  830. *size = vsp_cmd.sub_data.length_out;
  831. else
  832. rc = -ENOMEM;
  833. }
  834. iseries_hv_unmap(dma_addr, len, DMA_FROM_DEVICE);
  835. return rc;
  836. }
  837. static int proc_mf_dump_vmlinux(char *page, char **start, off_t off,
  838. int count, int *eof, void *data)
  839. {
  840. int sizeToGet = count;
  841. if (!capable(CAP_SYS_ADMIN))
  842. return -EACCES;
  843. if (mf_getVmlinuxChunk(page, &sizeToGet, off, (u64)data) == 0) {
  844. if (sizeToGet != 0) {
  845. *start = page + off;
  846. return sizeToGet;
  847. }
  848. *eof = 1;
  849. return 0;
  850. }
  851. *eof = 1;
  852. return 0;
  853. }
  854. #endif
  855. static int mf_side_proc_show(struct seq_file *m, void *v)
  856. {
  857. char mf_current_side = ' ';
  858. struct vsp_cmd_data vsp_cmd;
  859. memset(&vsp_cmd, 0, sizeof(vsp_cmd));
  860. vsp_cmd.cmd = 2;
  861. vsp_cmd.sub_data.ipl_type = 0;
  862. mb();
  863. if (signal_vsp_instruction(&vsp_cmd) == 0) {
  864. if (vsp_cmd.result_code == 0) {
  865. switch (vsp_cmd.sub_data.ipl_type) {
  866. case 0: mf_current_side = 'A';
  867. break;
  868. case 1: mf_current_side = 'B';
  869. break;
  870. case 2: mf_current_side = 'C';
  871. break;
  872. default: mf_current_side = 'D';
  873. break;
  874. }
  875. }
  876. }
  877. seq_printf(m, "%c\n", mf_current_side);
  878. return 0;
  879. }
  880. static int mf_side_proc_open(struct inode *inode, struct file *file)
  881. {
  882. return single_open(file, mf_side_proc_show, NULL);
  883. }
  884. static ssize_t mf_side_proc_write(struct file *file, const char __user *buffer,
  885. size_t count, loff_t *pos)
  886. {
  887. char side;
  888. u64 newSide;
  889. struct vsp_cmd_data vsp_cmd;
  890. if (!capable(CAP_SYS_ADMIN))
  891. return -EACCES;
  892. if (count == 0)
  893. return 0;
  894. if (get_user(side, buffer))
  895. return -EFAULT;
  896. switch (side) {
  897. case 'A': newSide = 0;
  898. break;
  899. case 'B': newSide = 1;
  900. break;
  901. case 'C': newSide = 2;
  902. break;
  903. case 'D': newSide = 3;
  904. break;
  905. default:
  906. printk(KERN_ERR "mf_proc.c: proc_mf_change_side: invalid side\n");
  907. return -EINVAL;
  908. }
  909. memset(&vsp_cmd, 0, sizeof(vsp_cmd));
  910. vsp_cmd.sub_data.ipl_type = newSide;
  911. vsp_cmd.cmd = 10;
  912. (void)signal_vsp_instruction(&vsp_cmd);
  913. return count;
  914. }
  915. static const struct file_operations mf_side_proc_fops = {
  916. .owner = THIS_MODULE,
  917. .open = mf_side_proc_open,
  918. .read = seq_read,
  919. .llseek = seq_lseek,
  920. .release = single_release,
  921. .write = mf_side_proc_write,
  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 mf_src_proc_show(struct seq_file *m, void *v)
  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 mf_src_proc_open(struct inode *inode, struct file *file)
  985. {
  986. return single_open(file, mf_src_proc_show, NULL);
  987. }
  988. static ssize_t mf_src_proc_write(struct file *file, const char __user *buffer,
  989. size_t count, loff_t *pos)
  990. {
  991. char stkbuf[10];
  992. if (!capable(CAP_SYS_ADMIN))
  993. return -EACCES;
  994. if ((count < 4) && (count != 1)) {
  995. printk(KERN_ERR "mf_proc: invalid src\n");
  996. return -EINVAL;
  997. }
  998. if (count > (sizeof(stkbuf) - 1))
  999. count = sizeof(stkbuf) - 1;
  1000. if (copy_from_user(stkbuf, buffer, count))
  1001. return -EFAULT;
  1002. if ((count == 1) && (*stkbuf == '\0'))
  1003. mf_clear_src();
  1004. else
  1005. mf_display_src(*(u32 *)stkbuf);
  1006. return count;
  1007. }
  1008. static const struct file_operations mf_src_proc_fops = {
  1009. .owner = THIS_MODULE,
  1010. .open = mf_src_proc_open,
  1011. .read = seq_read,
  1012. .llseek = seq_lseek,
  1013. .release = single_release,
  1014. .write = mf_src_proc_write,
  1015. };
  1016. static ssize_t mf_cmdline_proc_write(struct file *file, const char __user *buffer,
  1017. size_t count, loff_t *pos)
  1018. {
  1019. void *data = PDE(file->f_path.dentry->d_inode)->data;
  1020. struct vsp_cmd_data vsp_cmd;
  1021. dma_addr_t dma_addr;
  1022. char *page;
  1023. int ret = -EACCES;
  1024. if (!capable(CAP_SYS_ADMIN))
  1025. goto out;
  1026. dma_addr = 0;
  1027. page = iseries_hv_alloc(count, &dma_addr, GFP_ATOMIC);
  1028. ret = -ENOMEM;
  1029. if (page == NULL)
  1030. goto out;
  1031. ret = -EFAULT;
  1032. if (copy_from_user(page, buffer, count))
  1033. goto out_free;
  1034. memset(&vsp_cmd, 0, sizeof(vsp_cmd));
  1035. vsp_cmd.cmd = 31;
  1036. vsp_cmd.sub_data.kern.token = dma_addr;
  1037. vsp_cmd.sub_data.kern.address_type = HvLpDma_AddressType_TceIndex;
  1038. vsp_cmd.sub_data.kern.side = (u64)data;
  1039. vsp_cmd.sub_data.kern.length = count;
  1040. mb();
  1041. (void)signal_vsp_instruction(&vsp_cmd);
  1042. ret = count;
  1043. out_free:
  1044. iseries_hv_free(count, page, dma_addr);
  1045. out:
  1046. return ret;
  1047. }
  1048. static const struct file_operations mf_cmdline_proc_fops = {
  1049. .owner = THIS_MODULE,
  1050. .open = mf_cmdline_proc_open,
  1051. .read = seq_read,
  1052. .llseek = seq_lseek,
  1053. .release = single_release,
  1054. .write = mf_cmdline_proc_write,
  1055. };
  1056. static ssize_t proc_mf_change_vmlinux(struct file *file,
  1057. const char __user *buf,
  1058. size_t count, loff_t *ppos)
  1059. {
  1060. struct proc_dir_entry *dp = PDE(file->f_path.dentry->d_inode);
  1061. ssize_t rc;
  1062. dma_addr_t dma_addr;
  1063. char *page;
  1064. struct vsp_cmd_data vsp_cmd;
  1065. rc = -EACCES;
  1066. if (!capable(CAP_SYS_ADMIN))
  1067. goto out;
  1068. dma_addr = 0;
  1069. page = iseries_hv_alloc(count, &dma_addr, GFP_ATOMIC);
  1070. rc = -ENOMEM;
  1071. if (page == NULL) {
  1072. printk(KERN_ERR "mf.c: couldn't allocate memory to set vmlinux chunk\n");
  1073. goto out;
  1074. }
  1075. rc = -EFAULT;
  1076. if (copy_from_user(page, buf, count))
  1077. goto out_free;
  1078. memset(&vsp_cmd, 0, sizeof(vsp_cmd));
  1079. vsp_cmd.cmd = 30;
  1080. vsp_cmd.sub_data.kern.token = dma_addr;
  1081. vsp_cmd.sub_data.kern.address_type = HvLpDma_AddressType_TceIndex;
  1082. vsp_cmd.sub_data.kern.side = (u64)dp->data;
  1083. vsp_cmd.sub_data.kern.offset = *ppos;
  1084. vsp_cmd.sub_data.kern.length = count;
  1085. mb();
  1086. rc = signal_vsp_instruction(&vsp_cmd);
  1087. if (rc)
  1088. goto out_free;
  1089. rc = -ENOMEM;
  1090. if (vsp_cmd.result_code != 0)
  1091. goto out_free;
  1092. *ppos += count;
  1093. rc = count;
  1094. out_free:
  1095. iseries_hv_free(count, page, dma_addr);
  1096. out:
  1097. return rc;
  1098. }
  1099. static const struct file_operations proc_vmlinux_operations = {
  1100. .write = proc_mf_change_vmlinux,
  1101. };
  1102. static int __init mf_proc_init(void)
  1103. {
  1104. struct proc_dir_entry *mf_proc_root;
  1105. struct proc_dir_entry *ent;
  1106. struct proc_dir_entry *mf;
  1107. char name[2];
  1108. int i;
  1109. if (!firmware_has_feature(FW_FEATURE_ISERIES))
  1110. return 0;
  1111. mf_proc_root = proc_mkdir("iSeries/mf", NULL);
  1112. if (!mf_proc_root)
  1113. return 1;
  1114. name[1] = '\0';
  1115. for (i = 0; i < 4; i++) {
  1116. name[0] = 'A' + i;
  1117. mf = proc_mkdir(name, mf_proc_root);
  1118. if (!mf)
  1119. return 1;
  1120. ent = proc_create_data("cmdline", S_IRUSR|S_IWUSR, mf,
  1121. &mf_cmdline_proc_fops, (void *)(long)i);
  1122. if (!ent)
  1123. return 1;
  1124. if (i == 3) /* no vmlinux entry for 'D' */
  1125. continue;
  1126. ent = proc_create_data("vmlinux", S_IFREG|S_IWUSR, mf,
  1127. &proc_vmlinux_operations,
  1128. (void *)(long)i);
  1129. if (!ent)
  1130. return 1;
  1131. }
  1132. ent = proc_create("side", S_IFREG|S_IRUSR|S_IWUSR, mf_proc_root,
  1133. &mf_side_proc_fops);
  1134. if (!ent)
  1135. return 1;
  1136. ent = proc_create("src", S_IFREG|S_IRUSR|S_IWUSR, mf_proc_root,
  1137. &mf_src_proc_fops);
  1138. if (!ent)
  1139. return 1;
  1140. return 0;
  1141. }
  1142. __initcall(mf_proc_init);
  1143. #endif /* CONFIG_PROC_FS */
  1144. /*
  1145. * Get the RTC from the virtual service processor
  1146. * This requires flowing LpEvents to the primary partition
  1147. */
  1148. void iSeries_get_rtc_time(struct rtc_time *rtc_tm)
  1149. {
  1150. mf_get_rtc(rtc_tm);
  1151. rtc_tm->tm_mon--;
  1152. }
  1153. /*
  1154. * Set the RTC in the virtual service processor
  1155. * This requires flowing LpEvents to the primary partition
  1156. */
  1157. int iSeries_set_rtc_time(struct rtc_time *tm)
  1158. {
  1159. mf_set_rtc(tm);
  1160. return 0;
  1161. }
  1162. unsigned long iSeries_get_boot_time(void)
  1163. {
  1164. struct rtc_time tm;
  1165. mf_get_boot_rtc(&tm);
  1166. return mktime(tm.tm_year + 1900, tm.tm_mon, tm.tm_mday,
  1167. tm.tm_hour, tm.tm_min, tm.tm_sec);
  1168. }