mf.c 31 KB

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