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

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