mf.c 32 KB

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