Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 | /* * mf.c * Copyright (C) 2001 Troy D. Armstrong IBM Corporation * * This modules exists as an interface between a Linux secondary partition * running on an iSeries and the primary partition's Virtual Service * Processor (VSP) object. The VSP has final authority over powering on/off * all partitions in the iSeries. It also provides miscellaneous low-level * machine facility type operations. * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <asm/iSeries/mf.h> #include <linux/types.h> #include <linux/errno.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/mm.h> #include <asm/iSeries/HvLpConfig.h> #include <linux/slab.h> #include <linux/delay.h> #include <asm/nvram.h> #include <asm/time.h> #include <asm/iSeries/ItSpCommArea.h> #include <asm/iSeries/mf_proc.h> #include <asm/iSeries/iSeries_proc.h> #include <asm/uaccess.h> #include <linux/pci.h> #include <linux/bcd.h> extern struct pci_dev * iSeries_vio_dev; /* * This is the structure layout for the Machine Facilites LPAR event * flows. */ struct VspCmdData; struct CeMsgData; union SafeCast { u64 ptrAsU64; void *ptr; }; typedef void (*CeMsgCompleteHandler)( void *token, struct CeMsgData *vspCmdRsp ); struct CeMsgCompleteData { CeMsgCompleteHandler xHdlr; void *xToken; }; struct VspRspData { struct semaphore *xSemaphore; struct VspCmdData *xResponse; }; struct IoMFLpEvent { struct HvLpEvent xHvLpEvent; u16 xSubtypeRc; u16 xRsvd1; u32 xRsvd2; union { struct AllocData { u16 xSize; u16 xType; u32 xCount; u16 xRsvd3; u8 xRsvd4; HvLpIndex xTargetLp; } xAllocData; struct CeMsgData { u8 xCEMsg[12]; char xReserved[4]; struct CeMsgCompleteData *xToken; } xCEMsgData; struct VspCmdData { union SafeCast xTokenUnion; u16 xCmd; HvLpIndex xLpIndex; u8 xRc; u32 xReserved1; union VspCmdSubData { struct { u64 xState; } xGetStateOut; struct { u64 xIplType; } xGetIplTypeOut, xFunction02SelectIplTypeIn; struct { u64 xIplMode; } xGetIplModeOut, xFunction02SelectIplModeIn; struct { u64 xPage[4]; } xGetSrcHistoryIn; struct { u64 xFlag; } xGetAutoIplWhenPrimaryIplsOut, xSetAutoIplWhenPrimaryIplsIn, xWhiteButtonPowerOffIn, xFunction08FastPowerOffIn, xIsSpcnRackPowerIncompleteOut; struct { u64 xToken; u64 xAddressType; u64 xSide; u32 xTransferLength; u32 xOffset; } xSetKernelImageIn, xGetKernelImageIn, xSetKernelCmdLineIn, xGetKernelCmdLineIn; struct { u32 xTransferLength; } xGetKernelImageOut,xGetKernelCmdLineOut; u8 xReserved2[80]; } xSubData; } xVspCmd; } xUnion; }; /* * All outgoing event traffic is kept on a FIFO queue. The first * pointer points to the one that is outstanding, and all new * requests get stuck on the end. Also, we keep a certain number of * preallocated stack elements so that we can operate very early in * the boot up sequence (before kmalloc is ready). */ struct StackElement { struct StackElement * next; struct IoMFLpEvent event; MFCompleteHandler hdlr; char dmaData[72]; unsigned dmaDataLength; unsigned remoteAddress; }; static spinlock_t spinlock; static struct StackElement * head = NULL; static struct StackElement * tail = NULL; static struct StackElement * avail = NULL; static struct StackElement prealloc[16]; /* * Put a stack element onto the available queue, so it can get reused. * Attention! You must have the spinlock before calling! */ void free( struct StackElement * element ) { if ( element != NULL ) { element->next = avail; avail = element; } } /* * Enqueue the outbound event onto the stack. If the queue was * empty to begin with, we must also issue it via the Hypervisor * interface. There is a section of code below that will touch * the first stack pointer without the protection of the spinlock. * This is OK, because we know that nobody else will be modifying * the first pointer when we do this. */ static int signalEvent( struct StackElement * newElement ) { int rc = 0; unsigned long flags; int go = 1; struct StackElement * element; HvLpEvent_Rc hvRc; /* enqueue the event */ if ( newElement != NULL ) { spin_lock_irqsave( &spinlock, flags ); if ( head == NULL ) head = newElement; else { go = 0; tail->next = newElement; } newElement->next = NULL; tail = newElement; spin_unlock_irqrestore( &spinlock, flags ); } /* send the event */ while ( go ) { go = 0; /* any DMA data to send beforehand? */ if ( head->dmaDataLength > 0 ) HvCallEvent_dmaToSp( head->dmaData, head->remoteAddress, head->dmaDataLength, HvLpDma_Direction_LocalToRemote ); hvRc = HvCallEvent_signalLpEvent(&head->event.xHvLpEvent); if ( hvRc != HvLpEvent_Rc_Good ) { printk( KERN_ERR "mf.c: HvCallEvent_signalLpEvent() failed with %d\n", (int)hvRc ); spin_lock_irqsave( &spinlock, flags ); element = head; head = head->next; if ( head != NULL ) go = 1; spin_unlock_irqrestore( &spinlock, flags ); if ( element == newElement ) rc = -EIO; else { if ( element->hdlr != NULL ) { union SafeCast mySafeCast; mySafeCast.ptrAsU64 = element->event.xHvLpEvent.xCorrelationToken; (*element->hdlr)( mySafeCast.ptr, -EIO ); } } spin_lock_irqsave( &spinlock, flags ); free( element ); spin_unlock_irqrestore( &spinlock, flags ); } } return rc; } /* * Allocate a new StackElement structure, and initialize it. */ static struct StackElement * newStackElement( void ) { struct StackElement * newElement = NULL; HvLpIndex primaryLp = HvLpConfig_getPrimaryLpIndex(); unsigned long flags; if ( newElement == NULL ) { spin_lock_irqsave( &spinlock, flags ); if ( avail != NULL ) { newElement = avail; avail = avail->next; } spin_unlock_irqrestore( &spinlock, flags ); } if ( newElement == NULL ) newElement = kmalloc(sizeof(struct StackElement),GFP_ATOMIC); if ( newElement == NULL ) { printk( KERN_ERR "mf.c: unable to kmalloc %ld bytes\n", sizeof(struct StackElement) ); return NULL; } memset( newElement, 0, sizeof(struct StackElement) ); newElement->event.xHvLpEvent.xFlags.xValid = 1; newElement->event.xHvLpEvent.xFlags.xAckType = HvLpEvent_AckType_ImmediateAck; newElement->event.xHvLpEvent.xFlags.xAckInd = HvLpEvent_AckInd_DoAck; newElement->event.xHvLpEvent.xFlags.xFunction = HvLpEvent_Function_Int; newElement->event.xHvLpEvent.xType = HvLpEvent_Type_MachineFac; newElement->event.xHvLpEvent.xSourceLp = HvLpConfig_getLpIndex(); newElement->event.xHvLpEvent.xTargetLp = primaryLp; newElement->event.xHvLpEvent.xSizeMinus1 = sizeof(newElement->event)-1; newElement->event.xHvLpEvent.xRc = HvLpEvent_Rc_Good; newElement->event.xHvLpEvent.xSourceInstanceId = HvCallEvent_getSourceLpInstanceId(primaryLp,HvLpEvent_Type_MachineFac); newElement->event.xHvLpEvent.xTargetInstanceId = HvCallEvent_getTargetLpInstanceId(primaryLp,HvLpEvent_Type_MachineFac); return newElement; } static int signalVspInstruction( struct VspCmdData *vspCmd ) { struct StackElement * newElement = newStackElement(); int rc = 0; struct VspRspData response; DECLARE_MUTEX_LOCKED(Semaphore); response.xSemaphore = &Semaphore; response.xResponse = vspCmd; if ( newElement == NULL ) rc = -ENOMEM; else { newElement->event.xHvLpEvent.xSubtype = 6; newElement->event.xHvLpEvent.x.xSubtypeData = ('M'<<24)+('F'<<16)+('V'<<8)+('I'<<0); newElement->event.xUnion.xVspCmd.xTokenUnion.ptr = &response; newElement->event.xUnion.xVspCmd.xCmd = vspCmd->xCmd; newElement->event.xUnion.xVspCmd.xLpIndex = HvLpConfig_getLpIndex(); newElement->event.xUnion.xVspCmd.xRc = 0xFF; newElement->event.xUnion.xVspCmd.xReserved1 = 0; memcpy(&(newElement->event.xUnion.xVspCmd.xSubData),&(vspCmd->xSubData), sizeof(vspCmd->xSubData)); mb(); rc = signalEvent(newElement); } if (rc == 0) { down(&Semaphore); } return rc; } /* * Send a 12-byte CE message to the primary partition VSP object */ static int signalCEMsg( char * ceMsg, void * token ) { struct StackElement * newElement = newStackElement(); int rc = 0; if ( newElement == NULL ) rc = -ENOMEM; else { newElement->event.xHvLpEvent.xSubtype = 0; newElement->event.xHvLpEvent.x.xSubtypeData = ('M'<<24)+('F'<<16)+('C'<<8)+('E'<<0); memcpy( newElement->event.xUnion.xCEMsgData.xCEMsg, ceMsg, 12 ); newElement->event.xUnion.xCEMsgData.xToken = token; rc = signalEvent(newElement); } return rc; } /* * Send a 12-byte CE message and DMA data to the primary partition VSP object */ static int dmaAndSignalCEMsg( char * ceMsg, void * token, void * dmaData, unsigned dmaDataLength, unsigned remoteAddress ) { struct StackElement * newElement = newStackElement(); int rc = 0; if ( newElement == NULL ) rc = -ENOMEM; else { newElement->event.xHvLpEvent.xSubtype = 0; newElement->event.xHvLpEvent.x.xSubtypeData = ('M'<<24)+('F'<<16)+('C'<<8)+('E'<<0); memcpy( newElement->event.xUnion.xCEMsgData.xCEMsg, ceMsg, 12 ); newElement->event.xUnion.xCEMsgData.xToken = token; memcpy( newElement->dmaData, dmaData, dmaDataLength ); newElement->dmaDataLength = dmaDataLength; newElement->remoteAddress = remoteAddress; rc = signalEvent(newElement); } return rc; } /* * Initiate a nice (hopefully) shutdown of Linux. We simply are * going to try and send the init process a SIGINT signal. If * this fails (why?), we'll simply force it off in a not-so-nice * manner. */ static int shutdown( void ) { int rc = kill_proc(1,SIGINT,1); if ( rc ) { printk( KERN_ALERT "mf.c: SIGINT to init failed (%d), hard shutdown commencing\n", rc ); mf_powerOff(); } else printk( KERN_INFO "mf.c: init has been successfully notified to proceed with shutdown\n" ); return rc; } /* * The primary partition VSP object is sending us a new * event flow. Handle it... */ static void intReceived( struct IoMFLpEvent * event ) { int freeIt = 0; struct StackElement * two = NULL; /* ack the interrupt */ event->xHvLpEvent.xRc = HvLpEvent_Rc_Good; HvCallEvent_ackLpEvent( &event->xHvLpEvent ); /* process interrupt */ switch( event->xHvLpEvent.xSubtype ) { case 0: /* CE message */ switch( event->xUnion.xCEMsgData.xCEMsg[3] ) { case 0x5B: /* power control notification */ if ( (event->xUnion.xCEMsgData.xCEMsg[5]&0x20) != 0 ) { printk( KERN_INFO "mf.c: Commencing partition shutdown\n" ); if ( shutdown() == 0 ) signalCEMsg( "\x00\x00\x00\xDB\x00\x00\x00\x00\x00\x00\x00\x00", NULL ); } break; case 0xC0: /* get time */ { if ( (head != NULL) && ( head->event.xUnion.xCEMsgData.xCEMsg[3] == 0x40 ) ) { freeIt = 1; if ( head->event.xUnion.xCEMsgData.xToken != 0 ) { CeMsgCompleteHandler xHdlr = head->event.xUnion.xCEMsgData.xToken->xHdlr; void * token = head->event.xUnion.xCEMsgData.xToken->xToken; if (xHdlr != NULL) (*xHdlr)( token, &(event->xUnion.xCEMsgData) ); } } } break; } /* remove from queue */ if ( freeIt == 1 ) { unsigned long flags; spin_lock_irqsave( &spinlock, flags ); if ( head != NULL ) { struct StackElement *oldHead = head; head = head->next; two = head; free( oldHead ); } spin_unlock_irqrestore( &spinlock, flags ); } /* send next waiting event */ if ( two != NULL ) signalEvent( NULL ); break; case 1: /* IT sys shutdown */ printk( KERN_INFO "mf.c: Commencing system shutdown\n" ); shutdown(); break; } } /* * The primary partition VSP object is acknowledging the receipt * of a flow we sent to them. If there are other flows queued * up, we must send another one now... */ static void ackReceived( struct IoMFLpEvent * event ) { unsigned long flags; struct StackElement * two = NULL; unsigned long freeIt = 0; /* handle current event */ if ( head != NULL ) { switch( event->xHvLpEvent.xSubtype ) { case 0: /* CE msg */ if ( event->xUnion.xCEMsgData.xCEMsg[3] == 0x40 ) { if ( event->xUnion.xCEMsgData.xCEMsg[2] != 0 ) { freeIt = 1; if ( head->event.xUnion.xCEMsgData.xToken != 0 ) { CeMsgCompleteHandler xHdlr = head->event.xUnion.xCEMsgData.xToken->xHdlr; void * token = head->event.xUnion.xCEMsgData.xToken->xToken; if (xHdlr != NULL) (*xHdlr)( token, &(event->xUnion.xCEMsgData) ); } } } else { freeIt = 1; } break; case 4: /* allocate */ case 5: /* deallocate */ if ( head->hdlr != NULL ) { union SafeCast mySafeCast; mySafeCast.ptrAsU64 = event->xHvLpEvent.xCorrelationToken; (*head->hdlr)( mySafeCast.ptr, event->xUnion.xAllocData.xCount ); } freeIt = 1; break; case 6: { struct VspRspData *rsp = (struct VspRspData *)event->xUnion.xVspCmd.xTokenUnion.ptr; if (rsp != NULL) { if (rsp->xResponse != NULL) memcpy(rsp->xResponse, &(event->xUnion.xVspCmd), sizeof(event->xUnion.xVspCmd)); if (rsp->xSemaphore != NULL) up(rsp->xSemaphore); } else { printk( KERN_ERR "mf.c: no rsp\n"); } freeIt = 1; } break; } } else printk( KERN_ERR "mf.c: stack empty for receiving ack\n" ); /* remove from queue */ spin_lock_irqsave( &spinlock, flags ); if (( head != NULL ) && ( freeIt == 1 )) { struct StackElement *oldHead = head; head = head->next; two = head; free( oldHead ); } spin_unlock_irqrestore( &spinlock, flags ); /* send next waiting event */ if ( two != NULL ) signalEvent( NULL ); } /* * This is the generic event handler we are registering with * the Hypervisor. Ensure the flows are for us, and then * parse it enough to know if it is an interrupt or an * acknowledge. */ static void hvHandler( struct HvLpEvent * event, struct pt_regs * regs ) { if ( (event != NULL) && (event->xType == HvLpEvent_Type_MachineFac) ) { switch( event->xFlags.xFunction ) { case HvLpEvent_Function_Ack: ackReceived( (struct IoMFLpEvent *)event ); break; case HvLpEvent_Function_Int: intReceived( (struct IoMFLpEvent *)event ); break; default: printk( KERN_ERR "mf.c: non ack/int event received\n" ); break; } } else printk( KERN_ERR "mf.c: alien event received\n" ); } /* * Global kernel interface to allocate and seed events into the * Hypervisor. */ void mf_allocateLpEvents( HvLpIndex targetLp, HvLpEvent_Type type, unsigned size, unsigned count, MFCompleteHandler hdlr, void * userToken ) { struct StackElement * newElement = newStackElement(); int rc = 0; if ( newElement == NULL ) rc = -ENOMEM; else { union SafeCast mine; mine.ptr = userToken; newElement->event.xHvLpEvent.xSubtype = 4; newElement->event.xHvLpEvent.xCorrelationToken = mine.ptrAsU64; newElement->event.xHvLpEvent.x.xSubtypeData = ('M'<<24)+('F'<<16)+('M'<<8)+('A'<<0); newElement->event.xUnion.xAllocData.xTargetLp = targetLp; newElement->event.xUnion.xAllocData.xType = type; newElement->event.xUnion.xAllocData.xSize = size; newElement->event.xUnion.xAllocData.xCount = count; newElement->hdlr = hdlr; rc = signalEvent(newElement); } if ( (rc != 0) && (hdlr != NULL) ) (*hdlr)( userToken, rc ); } /* * Global kernel interface to unseed and deallocate events already in * Hypervisor. */ void mf_deallocateLpEvents( HvLpIndex targetLp, HvLpEvent_Type type, unsigned count, MFCompleteHandler hdlr, void * userToken ) { struct StackElement * newElement = newStackElement(); int rc = 0; if ( newElement == NULL ) rc = -ENOMEM; else { union SafeCast mine; mine.ptr = userToken; newElement->event.xHvLpEvent.xSubtype = 5; newElement->event.xHvLpEvent.xCorrelationToken = mine.ptrAsU64; newElement->event.xHvLpEvent.x.xSubtypeData = ('M'<<24)+('F'<<16)+('M'<<8)+('D'<<0); newElement->event.xUnion.xAllocData.xTargetLp = targetLp; newElement->event.xUnion.xAllocData.xType = type; newElement->event.xUnion.xAllocData.xCount = count; newElement->hdlr = hdlr; rc = signalEvent(newElement); } if ( (rc != 0) && (hdlr != NULL) ) (*hdlr)( userToken, rc ); } /* * Global kernel interface to tell the VSP object in the primary * partition to power this partition off. */ void mf_powerOff( void ) { printk( KERN_INFO "mf.c: Down it goes...\n" ); signalCEMsg( "\x00\x00\x00\x4D\x00\x00\x00\x00\x00\x00\x00\x00", NULL ); for (;;); } /* * Global kernel interface to tell the VSP object in the primary * partition to reboot this partition. */ void mf_reboot( void ) { printk( KERN_INFO "mf.c: Preparing to bounce...\n" ); signalCEMsg( "\x00\x00\x00\x4E\x00\x00\x00\x00\x00\x00\x00\x00", NULL ); for (;;); } /* * Display a single word SRC onto the VSP control panel. */ void mf_displaySrc( u32 word ) { u8 ce[12]; memcpy( ce, "\x00\x00\x00\x4A\x00\x00\x00\x01\x00\x00\x00\x00", 12 ); ce[8] = word>>24; ce[9] = word>>16; ce[10] = word>>8; ce[11] = word; signalCEMsg( ce, NULL ); } /* * Display a single word SRC of the form "PROGXXXX" on the VSP control panel. */ void mf_displayProgress( u16 value ) { u8 ce[12]; u8 src[72]; memcpy( ce, "\x00\x00\x04\x4A\x00\x00\x00\x48\x00\x00\x00\x00", 12 ); memcpy( src, "\x01\x00\x00\x01" "\x00\x00\x00\x00" "\x00\x00\x00\x00" "\x00\x00\x00\x00" "\x00\x00\x00\x00" "\x00\x00\x00\x00" "\x00\x00\x00\x00" "\x00\x00\x00\x00" "\x00\x00\x00\x00" "\x00\x00\x00\x00" "PROGxxxx" " ", 72 ); src[6] = value>>8; src[7] = value&255; src[44] = "0123456789ABCDEF"[(value>>12)&15]; src[45] = "0123456789ABCDEF"[(value>>8)&15]; src[46] = "0123456789ABCDEF"[(value>>4)&15]; src[47] = "0123456789ABCDEF"[value&15]; dmaAndSignalCEMsg( ce, NULL, src, sizeof(src), 9*64*1024 ); } /* * Clear the VSP control panel. Used to "erase" an SRC that was * previously displayed. */ void mf_clearSrc( void ) { signalCEMsg( "\x00\x00\x00\x4B\x00\x00\x00\x00\x00\x00\x00\x00", NULL ); } /* * Initialization code here. */ void mf_init( void ) { int i; /* initialize */ spin_lock_init( &spinlock ); for ( i = 0; i < sizeof(prealloc)/sizeof(*prealloc); ++i ) free( &prealloc[i] ); HvLpEvent_registerHandler( HvLpEvent_Type_MachineFac, &hvHandler ); /* virtual continue ack */ signalCEMsg( "\x00\x00\x00\x57\x00\x00\x00\x00\x00\x00\x00\x00", NULL ); /* initialization complete */ printk( KERN_NOTICE "mf.c: iSeries Linux LPAR Machine Facilities initialized\n" ); iSeries_proc_callback(&mf_proc_init); } void mf_setSide(char side) { int rc = 0; u64 newSide = 0; struct VspCmdData myVspCmd; memset(&myVspCmd, 0, sizeof(myVspCmd)); if (side == 'A') newSide = 0; else if (side == 'B') newSide = 1; else if (side == 'C') newSide = 2; else newSide = 3; myVspCmd.xSubData.xFunction02SelectIplTypeIn.xIplType = newSide; myVspCmd.xCmd = 10; rc = signalVspInstruction(&myVspCmd); } char mf_getSide(void) { char returnValue = ' '; int rc = 0; struct VspCmdData myVspCmd; memset(&myVspCmd, 0, sizeof(myVspCmd)); myVspCmd.xCmd = 2; myVspCmd.xSubData.xFunction02SelectIplTypeIn.xIplType = 0; mb(); rc = signalVspInstruction(&myVspCmd); if (rc != 0) { return returnValue; } else { if (myVspCmd.xRc == 0) { if (myVspCmd.xSubData.xGetIplTypeOut.xIplType == 0) returnValue = 'A'; else if (myVspCmd.xSubData.xGetIplTypeOut.xIplType == 1) returnValue = 'B'; else if (myVspCmd.xSubData.xGetIplTypeOut.xIplType == 2) returnValue = 'C'; else returnValue = 'D'; } } return returnValue; } void mf_getSrcHistory(char *buffer, int size) { /* struct IplTypeReturnStuff returnStuff; struct StackElement * newElement = newStackElement(); int rc = 0; char *pages[4]; pages[0] = kmalloc(4096, GFP_ATOMIC); pages[1] = kmalloc(4096, GFP_ATOMIC); pages[2] = kmalloc(4096, GFP_ATOMIC); pages[3] = kmalloc(4096, GFP_ATOMIC); if (( newElement == NULL ) || (pages[0] == NULL) || (pages[1] == NULL) || (pages[2] == NULL) || (pages[3] == NULL)) rc = -ENOMEM; else { returnStuff.xType = 0; returnStuff.xRc = 0; returnStuff.xDone = 0; newElement->event.xHvLpEvent.xSubtype = 6; newElement->event.xHvLpEvent.x.xSubtypeData = ('M'<<24)+('F'<<16)+('V'<<8)+('I'<<0); newElement->event.xUnion.xVspCmd.xEvent = &returnStuff; newElement->event.xUnion.xVspCmd.xCmd = 4; newElement->event.xUnion.xVspCmd.xLpIndex = HvLpConfig_getLpIndex(); newElement->event.xUnion.xVspCmd.xRc = 0xFF; newElement->event.xUnion.xVspCmd.xReserved1 = 0; newElement->event.xUnion.xVspCmd.xSubData.xGetSrcHistoryIn.xPage[0] = (0x8000000000000000ULL | virt_to_absolute((unsigned long)pages[0])); newElement->event.xUnion.xVspCmd.xSubData.xGetSrcHistoryIn.xPage[1] = (0x8000000000000000ULL | virt_to_absolute((unsigned long)pages[1])); newElement->event.xUnion.xVspCmd.xSubData.xGetSrcHistoryIn.xPage[2] = (0x8000000000000000ULL | virt_to_absolute((unsigned long)pages[2])); newElement->event.xUnion.xVspCmd.xSubData.xGetSrcHistoryIn.xPage[3] = (0x8000000000000000ULL | virt_to_absolute((unsigned long)pages[3])); mb(); rc = signalEvent(newElement); } if (rc != 0) { return; } else { while (returnStuff.xDone != 1) { udelay(10); } if (returnStuff.xRc == 0) { memcpy(buffer, pages[0], size); } } kfree(pages[0]); kfree(pages[1]); kfree(pages[2]); kfree(pages[3]);*/ } void mf_setCmdLine(const char *cmdline, int size, u64 side) { struct VspCmdData myVspCmd; int rc = 0; dma_addr_t dma_addr = 0; char *page = pci_alloc_consistent(iSeries_vio_dev, size, &dma_addr); if (page == NULL) { printk(KERN_ERR "mf.c: couldn't allocate memory to set command line\n"); return; } copy_from_user(page, cmdline, size); memset(&myVspCmd, 0, sizeof(myVspCmd)); myVspCmd.xCmd = 31; myVspCmd.xSubData.xSetKernelCmdLineIn.xToken = dma_addr; myVspCmd.xSubData.xSetKernelCmdLineIn.xAddressType = HvLpDma_AddressType_TceIndex; myVspCmd.xSubData.xSetKernelCmdLineIn.xSide = side; myVspCmd.xSubData.xSetKernelCmdLineIn.xTransferLength = size; mb(); rc = signalVspInstruction(&myVspCmd); pci_free_consistent(iSeries_vio_dev, size, page, dma_addr); } int mf_getCmdLine(char *cmdline, int *size, u64 side) { struct VspCmdData myVspCmd; int rc = 0; int len = *size; dma_addr_t dma_addr = pci_map_single(iSeries_vio_dev, cmdline, *size, PCI_DMA_FROMDEVICE); memset(cmdline, 0, *size); memset(&myVspCmd, 0, sizeof(myVspCmd)); myVspCmd.xCmd = 33; myVspCmd.xSubData.xGetKernelCmdLineIn.xToken = dma_addr; myVspCmd.xSubData.xGetKernelCmdLineIn.xAddressType = HvLpDma_AddressType_TceIndex; myVspCmd.xSubData.xGetKernelCmdLineIn.xSide = side; myVspCmd.xSubData.xGetKernelCmdLineIn.xTransferLength = *size; mb(); rc = signalVspInstruction(&myVspCmd); if ( ! rc ) { if (myVspCmd.xRc == 0) { len = myVspCmd.xSubData.xGetKernelCmdLineOut.xTransferLength; } /* else { memcpy(cmdline, "Bad cmdline", 11); } */ } pci_unmap_single(iSeries_vio_dev, dma_addr, *size, PCI_DMA_FROMDEVICE); return len; } int mf_setVmlinuxChunk(const char *buffer, int size, int offset, u64 side) { struct VspCmdData myVspCmd; int rc = 0; dma_addr_t dma_addr = 0; char *page = pci_alloc_consistent(iSeries_vio_dev, size, &dma_addr); if (page == NULL) { printk(KERN_ERR "mf.c: couldn't allocate memory to set vmlinux chunk\n"); return -ENOMEM; } copy_from_user(page, buffer, size); memset(&myVspCmd, 0, sizeof(myVspCmd)); myVspCmd.xCmd = 30; myVspCmd.xSubData.xGetKernelImageIn.xToken = dma_addr; myVspCmd.xSubData.xGetKernelImageIn.xAddressType = HvLpDma_AddressType_TceIndex; myVspCmd.xSubData.xGetKernelImageIn.xSide = side; myVspCmd.xSubData.xGetKernelImageIn.xOffset = offset; myVspCmd.xSubData.xGetKernelImageIn.xTransferLength = size; mb(); rc = signalVspInstruction(&myVspCmd); if (rc == 0) { if (myVspCmd.xRc == 0) { rc = 0; } else { rc = -ENOMEM; } } pci_free_consistent(iSeries_vio_dev, size, page, dma_addr); return rc; } int mf_getVmlinuxChunk(char *buffer, int *size, int offset, u64 side) { struct VspCmdData myVspCmd; int rc = 0; int len = *size; dma_addr_t dma_addr = pci_map_single(iSeries_vio_dev, buffer, *size, PCI_DMA_FROMDEVICE); memset(buffer, 0, len); memset(&myVspCmd, 0, sizeof(myVspCmd)); myVspCmd.xCmd = 32; myVspCmd.xSubData.xGetKernelImageIn.xToken = dma_addr; myVspCmd.xSubData.xGetKernelImageIn.xAddressType = HvLpDma_AddressType_TceIndex; myVspCmd.xSubData.xGetKernelImageIn.xSide = side; myVspCmd.xSubData.xGetKernelImageIn.xOffset = offset; myVspCmd.xSubData.xGetKernelImageIn.xTransferLength = len; mb(); rc = signalVspInstruction(&myVspCmd); if (rc == 0) { if (myVspCmd.xRc == 0) { *size = myVspCmd.xSubData.xGetKernelImageOut.xTransferLength; } else { rc = -ENOMEM; } } pci_unmap_single(iSeries_vio_dev, dma_addr, len, PCI_DMA_FROMDEVICE); return rc; } int mf_setRtcTime(unsigned long time) { struct rtc_time tm; to_tm(time, &tm); return mf_setRtc( &tm ); } struct RtcTimeData { struct semaphore *xSemaphore; struct CeMsgData xCeMsg; int xRc; }; void getRtcTimeComplete(void * token, struct CeMsgData *ceMsg) { struct RtcTimeData *rtc = (struct RtcTimeData *)token; memcpy(&(rtc->xCeMsg), ceMsg, sizeof(rtc->xCeMsg)); rtc->xRc = 0; up(rtc->xSemaphore); } static unsigned long lastsec = 1; int mf_getRtcTime(unsigned long *time) { /* unsigned long usec, tsec; */ u32 dataWord1 = *((u32 *)(&xSpCommArea.xBcdTimeAtIplStart)); u32 dataWord2 = *(((u32 *)&(xSpCommArea.xBcdTimeAtIplStart)) + 1); int year = 1970; int year1 = ( dataWord1 >> 24 ) & 0x000000FF; int year2 = ( dataWord1 >> 16 ) & 0x000000FF; int sec = ( dataWord1 >> 8 ) & 0x000000FF; int min = dataWord1 & 0x000000FF; int hour = ( dataWord2 >> 24 ) & 0x000000FF; int day = ( dataWord2 >> 8 ) & 0x000000FF; int mon = dataWord2 & 0x000000FF; BCD_TO_BIN(sec); BCD_TO_BIN(min); BCD_TO_BIN(hour); BCD_TO_BIN(day); BCD_TO_BIN(mon); BCD_TO_BIN(year1); BCD_TO_BIN(year2); year = year1 * 100 + year2; *time = mktime(year, mon, day, hour, min, sec); *time += ( jiffies / HZ ); /* Now THIS is a nasty hack! * It ensures that the first two calls to mf_getRtcTime get different * answers. That way the loop in init_time (time.c) will not think * the clock is stuck. */ if ( lastsec ) { *time -= lastsec; --lastsec; } return 0; } int mf_getRtc( struct rtc_time * tm ) { struct CeMsgCompleteData ceComplete; struct RtcTimeData rtcData; int rc = 0; DECLARE_MUTEX_LOCKED(Semaphore); memset(&ceComplete, 0, sizeof(ceComplete)); memset(&rtcData, 0, sizeof(rtcData)); rtcData.xSemaphore = &Semaphore; ceComplete.xHdlr = &getRtcTimeComplete; ceComplete.xToken = (void *)&rtcData; rc = signalCEMsg( "\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00", &ceComplete ); if ( rc == 0 ) { down(&Semaphore); if ( rtcData.xRc == 0) { if ( ( rtcData.xCeMsg.xCEMsg[2] == 0xa9 ) || ( rtcData.xCeMsg.xCEMsg[2] == 0xaf ) ) { /* TOD clock is not set */ tm->tm_sec = 1; tm->tm_min = 1; tm->tm_hour = 1; tm->tm_mday = 10; tm->tm_mon = 8; tm->tm_year = 71; mf_setRtc( tm ); } { u32 dataWord1 = *((u32 *)(rtcData.xCeMsg.xCEMsg+4)); u32 dataWord2 = *((u32 *)(rtcData.xCeMsg.xCEMsg+8)); u8 year = (dataWord1 >> 16 ) & 0x000000FF; u8 sec = ( dataWord1 >> 8 ) & 0x000000FF; u8 min = dataWord1 & 0x000000FF; u8 hour = ( dataWord2 >> 24 ) & 0x000000FF; u8 day = ( dataWord2 >> 8 ) & 0x000000FF; u8 mon = dataWord2 & 0x000000FF; BCD_TO_BIN(sec); BCD_TO_BIN(min); BCD_TO_BIN(hour); BCD_TO_BIN(day); BCD_TO_BIN(mon); BCD_TO_BIN(year); if ( year <= 69 ) year += 100; tm->tm_sec = sec; tm->tm_min = min; tm->tm_hour = hour; tm->tm_mday = day; tm->tm_mon = mon; tm->tm_year = year; } } else { rc = rtcData.xRc; tm->tm_sec = 0; tm->tm_min = 0; tm->tm_hour = 0; tm->tm_mday = 15; tm->tm_mon = 5; tm->tm_year = 52; } tm->tm_wday = 0; tm->tm_yday = 0; tm->tm_isdst = 0; } return rc; } int mf_setRtc(struct rtc_time * tm) { char ceTime[12] = "\x00\x00\x00\x41\x00\x00\x00\x00\x00\x00\x00\x00"; int rc = 0; u8 day, mon, hour, min, sec, y1, y2; unsigned year; year = 1900 + tm->tm_year; y1 = year / 100; y2 = year % 100; sec = tm->tm_sec; min = tm->tm_min; hour = tm->tm_hour; day = tm->tm_mday; mon = tm->tm_mon + 1; BIN_TO_BCD(sec); BIN_TO_BCD(min); BIN_TO_BCD(hour); BIN_TO_BCD(mon); BIN_TO_BCD(day); BIN_TO_BCD(y1); BIN_TO_BCD(y2); ceTime[4] = y1; ceTime[5] = y2; ceTime[6] = sec; ceTime[7] = min; ceTime[8] = hour; ceTime[10] = day; ceTime[11] = mon; rc = signalCEMsg( ceTime, NULL ); return rc; } |