mf.c 32 KB

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