mf.c 31 KB

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