iPXE
pcmcia.c
Go to the documentation of this file.
00001 #if 0
00002 
00003 /*
00004  *      pcmcia.c
00005  *
00006  *      PCMCIA support routines for etherboot - generic stuff
00007  *
00008  *      This code has partly be taken from the linux kernel sources, .../drivers/pcmcia/
00009  *      Started & put together by
00010  *              Anselm Martin Hoffmeister
00011  *              Stockholm Projekt Computer-Service
00012  *              Sankt Augustin / Bonn, Germany
00013  *
00014  *      Distributed under GPL2
00015  */
00016 
00017 /*
00018  *
00019  *
00020  *                      ******************************
00021  *                      PLEASE DO NOT YET WORK ON THIS
00022  *                      ******************************
00023  *
00024  *      I'm still fixing it up on every end, so we most probably would interfere
00025  *      at some point. If there's anything obvious or better, not-so-obvious,
00026  *      please contact me by e-mail: anselm (AT) hoffmeister (DOT) be   *THANKS*
00027  */
00028 
00029 FILE_LICENCE ( GPL2_ONLY );
00030 
00031 #include <stdio.h>
00032 #include <pcmcia.h>
00033 #include <i82365.h>
00034 #define CODE_STATUS "alpha"
00035 #define CODE_VERSION "0.1.3"
00036 #include <pcmcia-opts.h>
00037 #include <ipxe/init.h>
00038 
00039 int     sockets; /* AHTODO: Phase this out! */
00040 u_int   pccsocks;
00041 struct  pccsock_t pccsock[MAXPCCSOCKS];
00042 int     inited = -1;
00043 struct  pcc_config_t pccconfig[MAXPCCCONFIGS];
00044 
00045 struct  driver_interact_t driver[] = {
00046 #ifdef  SUPPORT_I82365
00047         { I82365, i82365_interfacer, "Intel_82365" },
00048 #endif
00049 };
00050 
00051 #define NUM_DRIVERS (sizeof(driver)/(sizeof(struct driver_interact_t)))
00052 
00053 void    sleepticks(int numticks ) {
00054         u_int   tmo;
00055         for (tmo = currticks()+numticks; currticks() < tmo; ) {
00056         }
00057         return;
00058 }
00059 
00060 static void pcmcia_init_all(void) {
00061         u_int i, j, k, l, m, n, ui, configs = 0;
00062         u_int multicard[8];
00063         u_char  *uc, upc;
00064         if ( PDEBUG > 0 ) printf("Initializing PCMCIA subsystem (code-status: " CODE_STATUS ", Version " CODE_VERSION ")\n");
00065         if ( PDEBUG > 2 ) {
00066                 printf ( "Supporting %d driver(s): ", NUM_DRIVERS );
00067                 for ( i = 0; i < NUM_DRIVERS; ++i ) {
00068                         printf ( "[%s] ", driver[i].name );
00069                 }
00070                 printf ( "\n" );
00071         }
00072         pccsocks = 0;
00073         sockets = 0;
00074         // Init all drivers in the driver[] array:
00075         for ( i = 0; i < NUM_DRIVERS; ++i ) {
00076                 driver[i].f(INIT,0,i,0,0);      // init needs no params. It uses pccsocks and pccsock[].
00077                                                 // Only i tells it which driver_id itself is.
00078         }
00079         for ( i = 0; i < pccsocks; ++i ) {
00080                 printf ( "Socket %d: ", i );
00081                 if ( pccsock[i].status != HASCARD ) {
00082                         printf ( "is %s: skipping\n", pccsock[i].status == EMPTY? "empty":"[status unknown]" );
00083                         continue;
00084                 }
00085                 if ( 0 != driver[pccsock[i].drivernum].f(MAPATTRMEM,pccsock[i].internalid,MAP_ATTRMEM_TO, MAP_ATTRMEM_LEN,0 ) ) {
00086                         printf ("PCMCIA controller failed to map attribute memory.\n**** SEVERE ERROR CONDITION. Skipping controller.\n" );
00087                         if ( PDEBUG > 2 ) {
00088                                 printf ( "<press key. THIS CONDITION SHOULD BE REPORTED!>\n" ); getchar();
00089                         }
00090                         continue;
00091                 }
00092                 // parse configuration information
00093                 uc = ioremap ( MAP_ATTRMEM_TO, MAP_ATTRMEM_LEN );
00094                 pccsock[i].stringoffset = pccsock[i].configoffset = pccsock[i].stringlength = 0;
00095                 pccsock[i].type = 0xff;
00096                 for ( l = 0; l < 8; ++l ) multicard[l] = 0;
00097                 sleepticks(2);
00098                 for ( l = ui = 0; ui < 0x800; ui += uc[(2*ui)+2] + 2 ) {
00099                         if ( uc[(2*ui)] == 0xff ) {
00100                                 break;
00101                         }
00102                         // This loop is complete rubbish AFAICS.
00103                         // But without it, my test system won't come up.
00104                         // It's too bad to develop on broken hardware
00105                         //                              - Anselm
00106                 }
00107                 sleepticks(2);
00108                 configs = 0;
00109                 inited = -1;
00110                 for ( l = ui = 0; ui < 0x800; ui += uc[(2*ui)+2] + 2 ) {
00111                         if ( uc[(2*ui)] == 0xff ) break;
00112                         else if ( uc[2*ui] == 0x15 ) {
00113                                 for ( k = 2 * ( ui + 2 ); ( uc[k] <= ' ' ) && ( k < ( 2 * ( uc[2*(ui+1)] + ui + 2 ) ) ) ; k += 2 ) { ; }
00114                                 pccsock[i].stringoffset = k;
00115                                 pccsock[i].stringlength = ( 2 * ( ui + 2 + uc[(2*ui)+2] ) - k ) / 2;
00116                         } else if ( uc[2*ui] == 0x21 ) {
00117                                 pccsock[i].type = uc[(2*ui)+4];
00118                         } else if ( uc[2*ui] == 0x1a ) { // Configuration map
00119                                 printf ( "\nConfig map 0x1a found [" );
00120                                 for ( k = 0; k < uc[2*(ui+1)]; ++k ) {
00121                                         printf ( "%02x ", uc[2*(ui+k+2)] );
00122                                 }
00123                                 printf ( "]\nHighest config available is %d\n", uc[2*(ui+3)] );
00124                                 m = uc[2*(ui+2)];
00125                                 pccsock[i].configoffset = 0;
00126                                 for ( j = 0; j <= (m & 3); ++j ) {
00127                                         pccsock[i].configoffset += uc[2*(ui+4+j)] << (8*j);
00128                                 }
00129                                 pccsock[i].rmask0 = 0;
00130                                 for ( j = 0; j <= ( ( ( m & 0x3c ) >> 2 ) & 3 ); ++j ) {
00131                                         pccsock[i].rmask0 += uc[2*(ui+5+(m&3)+j)] << (8*j);
00132                                 }
00133                                 j = pccsock[i].rmask0;
00134                                 printf ( "Config offset is %x, card has regs: < %s%s%s%s%s>\n", pccsock[i].configoffset,
00135                                         j & 1 ? "COR ":"", j & 2 ? "CCSR ":"", j & 4 ? "PRR ":"", j & 8 ? "SCR ":"", j & 16? "ESR ":"" );
00136                                 printf ( "COR + CCSR contents (si/du) %x %x/%x %x\n", uc[pccsock[i].configoffset+0],
00137                                         uc[pccsock[i].configoffset+2],uc[pccsock[i].configoffset*2],uc[(pccsock[i].configoffset*2)+2] );
00138                                 printf ( "          " );
00139                         } else if ( uc[2*ui] == 0x1b ) { // Configuration data entry
00140                                 //printf ( "Config data 0x1b found [\n" );getchar();
00141                                 for ( k = 0; k < uc[2*(ui+1)]; ++k ) {
00142                                 //      printf ( "%02x ", uc[2*(ui+k+2)] );
00143                                 }
00144                                 // Parse this tuple into pccconfig[configs]
00145                                 // printf ( "]\n" );
00146                                 if ( configs == MAXPCCCONFIGS ) continue;
00147                                 k = 2*ui+4;
00148                                 pccconfig[configs].index = uc[k] & 0x3f;
00149                                 if ( uc[k] & 0x80 ) {
00150                                 //      printf ( "Special config, unsupp. for now\n" );
00151                                         continue;
00152                                 }
00153                                 k+=2;
00154                                 // printf ( "Features: %2x\n", uc[k] );
00155                                 if ( uc[k] & 0x7 ) {
00156                                         // printf ( "Cannot work with Vcc/Timing configs right now\n" );
00157                                         continue;
00158                                 }
00159                                 pccconfig[configs].iowin = pccconfig[configs].iolen = 0;
00160                                 if ( 0 != ( uc[k] & 0x8 ) ) {
00161                                         k+=2;
00162                                         // printf ( "Reading IO config: " );
00163                                         if ( 0 == ( uc[k] & 0x80 ) ) {
00164                                         //      printf ( "Cannot work with auto/io config\n" );
00165                                                 continue;
00166                                         }
00167                                         k+=2;
00168                                         if ( 0 != ( uc[k] & 0x0f ) ) {
00169                                         //      printf ( "Don't support more than 1 iowin right now\n" );
00170                                                 continue;
00171                                         }
00172                                         j = (uc[k] & 0x30) >> 4;
00173                                         m = (uc[k] & 0xc0) >> 6;
00174                                         if ( 3 == j ) ++j;
00175                                         if ( 3 == m ) ++m;
00176                                         k += 2;
00177                                         pccconfig[configs].iowin = 0;
00178                                         pccconfig[configs].iolen = 1;
00179                                         for ( n = 0; n < j; ++n, k+=2 ) {
00180                                                 pccconfig[configs].iowin += uc[k] << (n*8);
00181                                         }
00182                                         for ( n = 0; n < m; ++n, k+=2 ) {
00183                                                 pccconfig[configs].iolen += uc[k] << (n*8);
00184                                         }
00185                                         // printf ( "io %x len %d (%d)\n", pccconfig[configs].iowin, pccconfig[configs].iolen,configs );
00186                                 }
00187                                 for ( j = 0; j < (uc[k] & 3); ++j ) {
00188                                 //      pccconfig[configs].iowin += (uc[k+(2*j)+2]) << (8*j);
00189                                 }
00190                                 ++configs;
00191                         }
00192                 }
00193                 if ( pccsock[i].stringoffset > 0 ) {    // If no identifier, it's not a valid CIS (as of documentation...)
00194                         printf ( "[" );
00195                         for ( k = 0; ( k <  pccsock[i].stringlength ) && ( k < 64 ); ++k ) {
00196                                 j = uc[pccsock[i].stringoffset + 2 * k];
00197                                 printf ( "%c", (j>=' '? j:' ' ) );
00198                         }
00199                         printf ("]\n          is type %d (", pccsock[i].type );
00200                         switch ( pccsock[i].type ) {
00201                           case  0x00:
00202                                 printf ( "MULTI" ); break;
00203                           case  0x01:
00204                                 printf ( "Memory" ); break;
00205                           case  0x02:
00206                                 printf ( "Serial" ); break;
00207                           case  0x03:
00208                                 printf ( "Parallel" ); break;
00209                           case  0x04:
00210                                 printf ( "Fixed" ); break;
00211                           case  0x05:
00212                                 printf ( "Video" ); break;
00213                           case  0x06:
00214                                 printf ( "Network" ); break;
00215                           case  0x07:
00216                                 printf ( "AIMS" ); break;
00217                           case  0x08:
00218                                 printf ( "SCSI" ); break;
00219                           case  0x106: // Special / homebrew to say "Multi/network"
00220                                 printf ( "MULTI, with Network" ); break; // AHTODO find a card for this
00221                           default:
00222                                 printf ( "UNSUPPORTED/UNKNOWN" );
00223                         }
00224                         printf ( ") with %d possible configuration(s)\n", configs );
00225                         // Now set dependency: If it's Network or multi->network, accept
00226                         if ( (inited <= 0 ) && (6 == (0xff & pccsock[i].type) ) && (0 < configs ) ) {
00227                                 printf ( "activating this device with ioport %x-%x (config #%d)\n", 
00228                                 pccconfig[0].iowin, pccconfig[0].iowin+pccconfig[0].iolen-1, pccconfig[0].index );
00229                                 inited = i;
00230                                 // And unmap attrmem ourselves!
00231                                 printf ( "Activating config..." );
00232                                 if ( m=driver[pccsock[i].drivernum].f(SELECTCONFIG,pccsock[i].internalid,pccconfig[0].index,0,&pccconfig[0]) ) {
00233                                         printf ("Failure(%d)!",m); inited = -1;
00234                                         driver[pccsock[i].drivernum].f(UNMAPATTRMEM,pccsock[i].internalid,0,0,0);
00235                                 }
00236                                 printf ( "done!\n" );
00237                                 continue;
00238                         }
00239                 } else {
00240                         printf ( "unsupported - no identifier string found in CIS\n" );
00241                 }
00242                 // unmap the PCMCIA device
00243                 if ( i != inited ) {
00244                     if ( 0 != driver[pccsock[i].drivernum].f(UNMAPATTRMEM,pccsock[i].internalid,0,0,0) ) {
00245                         printf ("PCMCIA controller failed to unmap attribute memory.\n**** SEVERE ERROR CONDITION ****\n" );
00246                         if ( PDEBUG > 2 ) {
00247                                 printf ( "<press key. THIS CONDITION SHOULD BE REPORTED!>\n" ); getchar();
00248                         }
00249                         continue;
00250                     }
00251                 }
00252         }
00253         if ( PDEBUG > 2 ) {
00254                 printf ( "<press key to exit the pcmcia_init_all routine>\n" );
00255                 getchar();
00256         }
00257 
00258 }
00259 
00260 static void     pcmcia_shutdown_all(void) {
00261         int i;
00262         //if ( PDEBUG > 2 ) {printf("<press key to continue>\n" ); getchar(); }
00263         for ( i = 0; i < pccsocks; ++i ) {
00264                 driver[pccsock[i].drivernum].f(SHUTDOWN,pccsock[i].internalid,0,0,0);
00265         }
00266         printf("Shutdown of PCMCIA subsystem completed");
00267 }
00268 
00269 #endif