You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pcmcia.c 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. #if 0
  2. /*
  3. * pcmcia.c
  4. *
  5. * PCMCIA support routines for etherboot - generic stuff
  6. *
  7. * This code has partly be taken from the linux kernel sources, .../drivers/pcmcia/
  8. * Started & put together by
  9. * Anselm Martin Hoffmeister
  10. * Stockholm Projekt Computer-Service
  11. * Sankt Augustin / Bonn, Germany
  12. *
  13. * Distributed under GPL2
  14. */
  15. /*
  16. *
  17. *
  18. * ******************************
  19. * PLEASE DO NOT YET WORK ON THIS
  20. * ******************************
  21. *
  22. * I'm still fixing it up on every end, so we most probably would interfere
  23. * at some point. If there's anything obvious or better, not-so-obvious,
  24. * please contact me by e-mail: anselm (AT) hoffmeister (DOT) be *THANKS*
  25. */
  26. FILE_LICENCE ( GPL2_ONLY );
  27. #include <stdio.h>
  28. #include <pcmcia.h>
  29. #include <i82365.h>
  30. #define CODE_STATUS "alpha"
  31. #define CODE_VERSION "0.1.3"
  32. #include <pcmcia-opts.h>
  33. #include <ipxe/init.h>
  34. int sockets; /* AHTODO: Phase this out! */
  35. u_int pccsocks;
  36. struct pccsock_t pccsock[MAXPCCSOCKS];
  37. int inited = -1;
  38. struct pcc_config_t pccconfig[MAXPCCCONFIGS];
  39. struct driver_interact_t driver[] = {
  40. #ifdef SUPPORT_I82365
  41. { I82365, i82365_interfacer, "Intel_82365" },
  42. #endif
  43. };
  44. #define NUM_DRIVERS (sizeof(driver)/(sizeof(struct driver_interact_t)))
  45. void sleepticks(int numticks ) {
  46. u_int tmo;
  47. for (tmo = currticks()+numticks; currticks() < tmo; ) {
  48. }
  49. return;
  50. }
  51. static void pcmcia_init_all(void) {
  52. u_int i, j, k, l, m, n, ui, configs = 0;
  53. u_int multicard[8];
  54. u_char *uc, upc;
  55. if ( PDEBUG > 0 ) printf("Initializing PCMCIA subsystem (code-status: " CODE_STATUS ", Version " CODE_VERSION ")\n");
  56. if ( PDEBUG > 2 ) {
  57. printf ( "Supporting %d driver(s): ", NUM_DRIVERS );
  58. for ( i = 0; i < NUM_DRIVERS; ++i ) {
  59. printf ( "[%s] ", driver[i].name );
  60. }
  61. printf ( "\n" );
  62. }
  63. pccsocks = 0;
  64. sockets = 0;
  65. // Init all drivers in the driver[] array:
  66. for ( i = 0; i < NUM_DRIVERS; ++i ) {
  67. driver[i].f(INIT,0,i,0,0); // init needs no params. It uses pccsocks and pccsock[].
  68. // Only i tells it which driver_id itself is.
  69. }
  70. for ( i = 0; i < pccsocks; ++i ) {
  71. printf ( "Socket %d: ", i );
  72. if ( pccsock[i].status != HASCARD ) {
  73. printf ( "is %s: skipping\n", pccsock[i].status == EMPTY? "empty":"[status unknown]" );
  74. continue;
  75. }
  76. if ( 0 != driver[pccsock[i].drivernum].f(MAPATTRMEM,pccsock[i].internalid,MAP_ATTRMEM_TO, MAP_ATTRMEM_LEN,0 ) ) {
  77. printf ("PCMCIA controller failed to map attribute memory.\n**** SEVERE ERROR CONDITION. Skipping controller.\n" );
  78. if ( PDEBUG > 2 ) {
  79. printf ( "<press key. THIS CONDITION SHOULD BE REPORTED!>\n" ); getchar();
  80. }
  81. continue;
  82. }
  83. // parse configuration information
  84. uc = ioremap ( MAP_ATTRMEM_TO, MAP_ATTRMEM_LEN );
  85. pccsock[i].stringoffset = pccsock[i].configoffset = pccsock[i].stringlength = 0;
  86. pccsock[i].type = 0xff;
  87. for ( l = 0; l < 8; ++l ) multicard[l] = 0;
  88. sleepticks(2);
  89. for ( l = ui = 0; ui < 0x800; ui += uc[(2*ui)+2] + 2 ) {
  90. if ( uc[(2*ui)] == 0xff ) {
  91. break;
  92. }
  93. // This loop is complete rubbish AFAICS.
  94. // But without it, my test system won't come up.
  95. // It's too bad to develop on broken hardware
  96. // - Anselm
  97. }
  98. sleepticks(2);
  99. configs = 0;
  100. inited = -1;
  101. for ( l = ui = 0; ui < 0x800; ui += uc[(2*ui)+2] + 2 ) {
  102. if ( uc[(2*ui)] == 0xff ) break;
  103. else if ( uc[2*ui] == 0x15 ) {
  104. for ( k = 2 * ( ui + 2 ); ( uc[k] <= ' ' ) && ( k < ( 2 * ( uc[2*(ui+1)] + ui + 2 ) ) ) ; k += 2 ) { ; }
  105. pccsock[i].stringoffset = k;
  106. pccsock[i].stringlength = ( 2 * ( ui + 2 + uc[(2*ui)+2] ) - k ) / 2;
  107. } else if ( uc[2*ui] == 0x21 ) {
  108. pccsock[i].type = uc[(2*ui)+4];
  109. } else if ( uc[2*ui] == 0x1a ) { // Configuration map
  110. printf ( "\nConfig map 0x1a found [" );
  111. for ( k = 0; k < uc[2*(ui+1)]; ++k ) {
  112. printf ( "%02x ", uc[2*(ui+k+2)] );
  113. }
  114. printf ( "]\nHighest config available is %d\n", uc[2*(ui+3)] );
  115. m = uc[2*(ui+2)];
  116. pccsock[i].configoffset = 0;
  117. for ( j = 0; j <= (m & 3); ++j ) {
  118. pccsock[i].configoffset += uc[2*(ui+4+j)] << (8*j);
  119. }
  120. pccsock[i].rmask0 = 0;
  121. for ( j = 0; j <= ( ( ( m & 0x3c ) >> 2 ) & 3 ); ++j ) {
  122. pccsock[i].rmask0 += uc[2*(ui+5+(m&3)+j)] << (8*j);
  123. }
  124. j = pccsock[i].rmask0;
  125. printf ( "Config offset is %x, card has regs: < %s%s%s%s%s>\n", pccsock[i].configoffset,
  126. j & 1 ? "COR ":"", j & 2 ? "CCSR ":"", j & 4 ? "PRR ":"", j & 8 ? "SCR ":"", j & 16? "ESR ":"" );
  127. printf ( "COR + CCSR contents (si/du) %x %x/%x %x\n", uc[pccsock[i].configoffset+0],
  128. uc[pccsock[i].configoffset+2],uc[pccsock[i].configoffset*2],uc[(pccsock[i].configoffset*2)+2] );
  129. printf ( " " );
  130. } else if ( uc[2*ui] == 0x1b ) { // Configuration data entry
  131. //printf ( "Config data 0x1b found [\n" );getchar();
  132. for ( k = 0; k < uc[2*(ui+1)]; ++k ) {
  133. // printf ( "%02x ", uc[2*(ui+k+2)] );
  134. }
  135. // Parse this tuple into pccconfig[configs]
  136. // printf ( "]\n" );
  137. if ( configs == MAXPCCCONFIGS ) continue;
  138. k = 2*ui+4;
  139. pccconfig[configs].index = uc[k] & 0x3f;
  140. if ( uc[k] & 0x80 ) {
  141. // printf ( "Special config, unsupp. for now\n" );
  142. continue;
  143. }
  144. k+=2;
  145. // printf ( "Features: %2x\n", uc[k] );
  146. if ( uc[k] & 0x7 ) {
  147. // printf ( "Cannot work with Vcc/Timing configs right now\n" );
  148. continue;
  149. }
  150. pccconfig[configs].iowin = pccconfig[configs].iolen = 0;
  151. if ( 0 != ( uc[k] & 0x8 ) ) {
  152. k+=2;
  153. // printf ( "Reading IO config: " );
  154. if ( 0 == ( uc[k] & 0x80 ) ) {
  155. // printf ( "Cannot work with auto/io config\n" );
  156. continue;
  157. }
  158. k+=2;
  159. if ( 0 != ( uc[k] & 0x0f ) ) {
  160. // printf ( "Don't support more than 1 iowin right now\n" );
  161. continue;
  162. }
  163. j = (uc[k] & 0x30) >> 4;
  164. m = (uc[k] & 0xc0) >> 6;
  165. if ( 3 == j ) ++j;
  166. if ( 3 == m ) ++m;
  167. k += 2;
  168. pccconfig[configs].iowin = 0;
  169. pccconfig[configs].iolen = 1;
  170. for ( n = 0; n < j; ++n, k+=2 ) {
  171. pccconfig[configs].iowin += uc[k] << (n*8);
  172. }
  173. for ( n = 0; n < m; ++n, k+=2 ) {
  174. pccconfig[configs].iolen += uc[k] << (n*8);
  175. }
  176. // printf ( "io %x len %d (%d)\n", pccconfig[configs].iowin, pccconfig[configs].iolen,configs );
  177. }
  178. for ( j = 0; j < (uc[k] & 3); ++j ) {
  179. // pccconfig[configs].iowin += (uc[k+(2*j)+2]) << (8*j);
  180. }
  181. ++configs;
  182. }
  183. }
  184. if ( pccsock[i].stringoffset > 0 ) { // If no identifier, it's not a valid CIS (as of documentation...)
  185. printf ( "[" );
  186. for ( k = 0; ( k < pccsock[i].stringlength ) && ( k < 64 ); ++k ) {
  187. j = uc[pccsock[i].stringoffset + 2 * k];
  188. printf ( "%c", (j>=' '? j:' ' ) );
  189. }
  190. printf ("]\n is type %d (", pccsock[i].type );
  191. switch ( pccsock[i].type ) {
  192. case 0x00:
  193. printf ( "MULTI" ); break;
  194. case 0x01:
  195. printf ( "Memory" ); break;
  196. case 0x02:
  197. printf ( "Serial" ); break;
  198. case 0x03:
  199. printf ( "Parallel" ); break;
  200. case 0x04:
  201. printf ( "Fixed" ); break;
  202. case 0x05:
  203. printf ( "Video" ); break;
  204. case 0x06:
  205. printf ( "Network" ); break;
  206. case 0x07:
  207. printf ( "AIMS" ); break;
  208. case 0x08:
  209. printf ( "SCSI" ); break;
  210. case 0x106: // Special / homebrew to say "Multi/network"
  211. printf ( "MULTI, with Network" ); break; // AHTODO find a card for this
  212. default:
  213. printf ( "UNSUPPORTED/UNKNOWN" );
  214. }
  215. printf ( ") with %d possible configuration(s)\n", configs );
  216. // Now set dependency: If it's Network or multi->network, accept
  217. if ( (inited <= 0 ) && (6 == (0xff & pccsock[i].type) ) && (0 < configs ) ) {
  218. printf ( "activating this device with ioport %x-%x (config #%d)\n",
  219. pccconfig[0].iowin, pccconfig[0].iowin+pccconfig[0].iolen-1, pccconfig[0].index );
  220. inited = i;
  221. // And unmap attrmem ourselves!
  222. printf ( "Activating config..." );
  223. if ( m=driver[pccsock[i].drivernum].f(SELECTCONFIG,pccsock[i].internalid,pccconfig[0].index,0,&pccconfig[0]) ) {
  224. printf ("Failure(%d)!",m); inited = -1;
  225. driver[pccsock[i].drivernum].f(UNMAPATTRMEM,pccsock[i].internalid,0,0,0);
  226. }
  227. printf ( "done!\n" );
  228. continue;
  229. }
  230. } else {
  231. printf ( "unsupported - no identifier string found in CIS\n" );
  232. }
  233. // unmap the PCMCIA device
  234. if ( i != inited ) {
  235. if ( 0 != driver[pccsock[i].drivernum].f(UNMAPATTRMEM,pccsock[i].internalid,0,0,0) ) {
  236. printf ("PCMCIA controller failed to unmap attribute memory.\n**** SEVERE ERROR CONDITION ****\n" );
  237. if ( PDEBUG > 2 ) {
  238. printf ( "<press key. THIS CONDITION SHOULD BE REPORTED!>\n" ); getchar();
  239. }
  240. continue;
  241. }
  242. }
  243. }
  244. if ( PDEBUG > 2 ) {
  245. printf ( "<press key to exit the pcmcia_init_all routine>\n" );
  246. getchar();
  247. }
  248. }
  249. static void pcmcia_shutdown_all(void) {
  250. int i;
  251. //if ( PDEBUG > 2 ) {printf("<press key to continue>\n" ); getchar(); }
  252. for ( i = 0; i < pccsocks; ++i ) {
  253. driver[pccsock[i].drivernum].f(SHUTDOWN,pccsock[i].internalid,0,0,0);
  254. }
  255. printf("Shutdown of PCMCIA subsystem completed");
  256. }
  257. #endif