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.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 "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. poll_interruptions();
  47. }
  48. return;
  49. }
  50. static void pcmcia_init_all(void) {
  51. u_int i, j, k, l, m, n, ui, configs = 0;
  52. u_int multicard[8];
  53. u_char *uc, upc;
  54. if ( PDEBUG > 0 ) printf("Initializing PCMCIA subsystem (code-status: " CODE_STATUS ", Version " CODE_VERSION ")\n");
  55. if ( PDEBUG > 2 ) {
  56. printf ( "Supporting %d driver(s): ", NUM_DRIVERS );
  57. for ( i = 0; i < NUM_DRIVERS; ++i ) {
  58. printf ( "[%s] ", driver[i].name );
  59. }
  60. printf ( "\n" );
  61. }
  62. pccsocks = 0;
  63. sockets = 0;
  64. // Init all drivers in the driver[] array:
  65. for ( i = 0; i < NUM_DRIVERS; ++i ) {
  66. driver[i].f(INIT,0,i,0,0); // init needs no params. It uses pccsocks and pccsock[].
  67. // Only i tells it which driver_id itself is.
  68. }
  69. for ( i = 0; i < pccsocks; ++i ) {
  70. printf ( "Socket %d: ", i );
  71. if ( pccsock[i].status != HASCARD ) {
  72. printf ( "is %s: skipping\n", pccsock[i].status == EMPTY? "empty":"[status unknown]" );
  73. continue;
  74. }
  75. if ( 0 != driver[pccsock[i].drivernum].f(MAPATTRMEM,pccsock[i].internalid,MAP_ATTRMEM_TO, MAP_ATTRMEM_LEN,0 ) ) {
  76. printf ("PCMCIA controller failed to map attribute memory.\n**** SEVERE ERROR CONDITION. Skipping controller.\n" );
  77. if ( PDEBUG > 2 ) {
  78. printf ( "<press key. THIS CONDITION SHOULD BE REPORTED!>\n" ); getchar();
  79. }
  80. continue;
  81. }
  82. // parse configuration information
  83. uc = ioremap ( MAP_ATTRMEM_TO, MAP_ATTRMEM_LEN );
  84. pccsock[i].stringoffset = pccsock[i].configoffset = pccsock[i].stringlength = 0;
  85. pccsock[i].type = 0xff;
  86. for ( l = 0; l < 8; ++l ) multicard[l] = 0;
  87. sleepticks(2);
  88. for ( l = ui = 0; ui < 0x800; ui += uc[(2*ui)+2] + 2 ) {
  89. if ( uc[(2*ui)] == 0xff ) {
  90. break;
  91. }
  92. // This loop is complete rubbish AFAICS.
  93. // But without it, my test system won't come up.
  94. // It's too bad to develop on broken hardware
  95. // - Anselm
  96. }
  97. sleepticks(2);
  98. configs = 0;
  99. inited = -1;
  100. for ( l = ui = 0; ui < 0x800; ui += uc[(2*ui)+2] + 2 ) {
  101. if ( uc[(2*ui)] == 0xff ) break;
  102. else if ( uc[2*ui] == 0x15 ) {
  103. for ( k = 2 * ( ui + 2 ); ( uc[k] <= ' ' ) && ( k < ( 2 * ( uc[2*(ui+1)] + ui + 2 ) ) ) ; k += 2 ) { ; }
  104. pccsock[i].stringoffset = k;
  105. pccsock[i].stringlength = ( 2 * ( ui + 2 + uc[(2*ui)+2] ) - k ) / 2;
  106. } else if ( uc[2*ui] == 0x21 ) {
  107. pccsock[i].type = uc[(2*ui)+4];
  108. } else if ( uc[2*ui] == 0x1a ) { // Configuration map
  109. printf ( "\nConfig map 0x1a found [" );
  110. for ( k = 0; k < uc[2*(ui+1)]; ++k ) {
  111. printf ( "%02x ", uc[2*(ui+k+2)] );
  112. }
  113. printf ( "]\nHighest config available is %d\n", uc[2*(ui+3)] );
  114. m = uc[2*(ui+2)];
  115. pccsock[i].configoffset = 0;
  116. for ( j = 0; j <= m & 3; ++j ) {
  117. pccsock[i].configoffset += uc[2*(ui+4+j)] << (8*j);
  118. }
  119. pccsock[i].rmask0 = 0;
  120. for ( j = 0; j <= ( ( ( m & 0x3c ) >> 2 ) & 3 ); ++j ) {
  121. pccsock[i].rmask0 += uc[2*(ui+5+(m&3)+j)] << (8*j);
  122. }
  123. j = pccsock[i].rmask0;
  124. printf ( "Config offset is %x, card has regs: < %s%s%s%s%s>\n", pccsock[i].configoffset,
  125. j & 1 ? "COR ":"", j & 2 ? "CCSR ":"", j & 4 ? "PRR ":"", j & 8 ? "SCR ":"", j & 16? "ESR ":"" );
  126. printf ( "COR + CCSR contents (si/du) %x %x/%x %x\n", uc[pccsock[i].configoffset+0],
  127. uc[pccsock[i].configoffset+2],uc[pccsock[i].configoffset*2],uc[(pccsock[i].configoffset*2)+2] );
  128. printf ( " " );
  129. } else if ( uc[2*ui] == 0x1b ) { // Configuration data entry
  130. //printf ( "Config data 0x1b found [\n" );getchar();
  131. for ( k = 0; k < uc[2*(ui+1)]; ++k ) {
  132. // printf ( "%02x ", uc[2*(ui+k+2)] );
  133. }
  134. // Parse this tuple into pccconfig[configs]
  135. // printf ( "]\n" );
  136. if ( configs == MAXPCCCONFIGS ) continue;
  137. k = 2*ui+4;
  138. pccconfig[configs].index = uc[k] & 0x3f;
  139. if ( uc[k] & 0x80 ) {
  140. // printf ( "Special config, unsupp. for now\n" );
  141. continue;
  142. }
  143. k+=2;
  144. // printf ( "Features: %2x\n", uc[k] );
  145. if ( uc[k] & 0x7 ) {
  146. // printf ( "Cannot work with Vcc/Timing configs right now\n" );
  147. continue;
  148. }
  149. pccconfig[configs].iowin = pccconfig[configs].iolen = 0;
  150. if ( 0 != ( uc[k] & 0x8 ) ) {
  151. k+=2;
  152. // printf ( "Reading IO config: " );
  153. if ( 0 == ( uc[k] & 0x80 ) ) {
  154. // printf ( "Cannot work with auto/io config\n" );
  155. continue;
  156. }
  157. k+=2;
  158. if ( 0 != ( uc[k] & 0x0f ) ) {
  159. // printf ( "Don't support more than 1 iowin right now\n" );
  160. continue;
  161. }
  162. j = (uc[k] & 0x30) >> 4;
  163. m = (uc[k] & 0xc0) >> 6;
  164. if ( 3 == j ) ++j;
  165. if ( 3 == m ) ++m;
  166. k += 2;
  167. pccconfig[configs].iowin = 0;
  168. pccconfig[configs].iolen = 1;
  169. for ( n = 0; n < j; ++n, k+=2 ) {
  170. pccconfig[configs].iowin += uc[k] << (n*8);
  171. }
  172. for ( n = 0; n < m; ++n, k+=2 ) {
  173. pccconfig[configs].iolen += uc[k] << (n*8);
  174. }
  175. // printf ( "io %x len %d (%d)\n", pccconfig[configs].iowin, pccconfig[configs].iolen,configs );
  176. }
  177. for ( j = 0; j < (uc[k] & 3); ++j ) {
  178. // pccconfig[configs].iowin += (uc[k+(2*j)+2]) << (8*j);
  179. }
  180. ++configs;
  181. }
  182. }
  183. if ( pccsock[i].stringoffset > 0 ) { // If no identifier, it's not a valid CIS (as of documentation...)
  184. printf ( "[" );
  185. for ( k = 0; ( k < pccsock[i].stringlength ) && ( k < 64 ); ++k ) {
  186. j = uc[pccsock[i].stringoffset + 2 * k];
  187. printf ( "%c", (j>=' '? j:' ' ) );
  188. }
  189. printf ("]\n is type %d (", pccsock[i].type );
  190. switch ( pccsock[i].type ) {
  191. case 0x00:
  192. printf ( "MULTI" ); break;
  193. case 0x01:
  194. printf ( "Memory" ); break;
  195. case 0x02:
  196. printf ( "Serial" ); break;
  197. case 0x03:
  198. printf ( "Parallel" ); break;
  199. case 0x04:
  200. printf ( "Fixed" ); break;
  201. case 0x05:
  202. printf ( "Video" ); break;
  203. case 0x06:
  204. printf ( "Network" ); break;
  205. case 0x07:
  206. printf ( "AIMS" ); break;
  207. case 0x08:
  208. printf ( "SCSI" ); break;
  209. case 0x106: // Special / homebrew to say "Multi/network"
  210. printf ( "MULTI, with Network" ); break; // AHTODO find a card for this
  211. default:
  212. printf ( "UNSUPPORTED/UNKNOWN" );
  213. }
  214. printf ( ") with %d possible configuration(s)\n", configs );
  215. // Now set dependency: If it's Network or multi->network, accept
  216. if ( (inited <= 0 ) && (6 == (0xff & pccsock[i].type) ) && (0 < configs ) ) {
  217. printf ( "activating this device with ioport %x-%x (config #%d)\n",
  218. pccconfig[0].iowin, pccconfig[0].iowin+pccconfig[0].iolen-1, pccconfig[0].index );
  219. inited = i;
  220. // And unmap attrmem ourselves!
  221. printf ( "Activating config..." );
  222. if ( m=driver[pccsock[i].drivernum].f(SELECTCONFIG,pccsock[i].internalid,pccconfig[0].index,0,&pccconfig[0]) ) {
  223. printf ("Failure(%d)!",m); inited = -1;
  224. driver[pccsock[i].drivernum].f(UNMAPATTRMEM,pccsock[i].internalid,0,0,0);
  225. }
  226. printf ( "done!\n" );
  227. continue;
  228. }
  229. } else {
  230. printf ( "unsupported - no identifier string found in CIS\n" );
  231. }
  232. // unmap the PCMCIA device
  233. if ( i != inited ) {
  234. if ( 0 != driver[pccsock[i].drivernum].f(UNMAPATTRMEM,pccsock[i].internalid,0,0,0) ) {
  235. printf ("PCMCIA controller failed to unmap attribute memory.\n**** SEVERE ERROR CONDITION ****\n" );
  236. if ( PDEBUG > 2 ) {
  237. printf ( "<press key. THIS CONDITION SHOULD BE REPORTED!>\n" ); getchar();
  238. }
  239. continue;
  240. }
  241. }
  242. }
  243. if ( PDEBUG > 2 ) {
  244. printf ( "<press key to exit the pcmcia_init_all routine>\n" );
  245. getchar();
  246. }
  247. }
  248. static void pcmcia_shutdown_all(void) {
  249. int i;
  250. //if ( PDEBUG > 2 ) {printf("<press key to continue>\n" ); getchar(); }
  251. for ( i = 0; i < pccsocks; ++i ) {
  252. driver[pccsock[i].drivernum].f(SHUTDOWN,pccsock[i].internalid,0,0,0);
  253. }
  254. printf("Shutdown of PCMCIA subsystem completed");
  255. }
  256. INIT_FN ( INIT_PCMCIA, pcmcia_init_all, NULL, pcmcia_shutdown_all );