pcmcia_cis.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380
  1. /* $OpenBSD: pcmcia_cis.c,v 1.20 2014/07/12 18:48:52 tedu Exp $ */
  2. /* $NetBSD: pcmcia_cis.c,v 1.9 1998/08/22 23:41:48 msaitoh Exp $ */
  3. /*
  4. * Copyright (c) 1997 Marc Horowitz. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. All advertising materials mentioning features or use of this software
  15. * must display the following acknowledgement:
  16. * This product includes software developed by Marc Horowitz.
  17. * 4. The name of the author may not be used to endorse or promote products
  18. * derived from this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  21. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  22. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  23. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  25. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  26. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  27. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  29. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. */
  31. #include <sys/types.h>
  32. #include <sys/param.h>
  33. #include <sys/systm.h>
  34. #include <sys/device.h>
  35. #include <sys/malloc.h>
  36. #include <dev/pcmcia/pcmciareg.h>
  37. #include <dev/pcmcia/pcmciachip.h>
  38. #include <dev/pcmcia/pcmciavar.h>
  39. #ifdef PCMCIACISDEBUG
  40. #define DPRINTF(arg) printf arg
  41. #else
  42. #define DPRINTF(arg)
  43. #endif
  44. #define PCMCIA_CIS_SIZE 1024
  45. struct cis_state {
  46. int count;
  47. int gotmfc;
  48. struct pcmcia_config_entry temp_cfe;
  49. struct pcmcia_config_entry *default_cfe;
  50. struct pcmcia_card *card;
  51. struct pcmcia_function *pf;
  52. };
  53. int pcmcia_parse_cis_tuple(struct pcmcia_tuple *, void *);
  54. uint8_t
  55. pcmcia_cis_read_1(struct pcmcia_tuple *tuple, bus_size_t idx)
  56. {
  57. if (tuple->flags & PTF_INDIRECT) {
  58. bus_space_write_1(tuple->memt, tuple->memh,
  59. tuple->indirect_ptr + PCMCIA_INDR_CONTROL, PCMCIA_ICR_ATTR);
  60. idx <<= tuple->addrshift;
  61. bus_space_write_1(tuple->memt, tuple->memh,
  62. tuple->indirect_ptr + PCMCIA_INDR_ADDRESS + 0, idx >> 0);
  63. bus_space_write_1(tuple->memt, tuple->memh,
  64. tuple->indirect_ptr + PCMCIA_INDR_ADDRESS + 1, idx >> 8);
  65. bus_space_write_1(tuple->memt, tuple->memh,
  66. tuple->indirect_ptr + PCMCIA_INDR_ADDRESS + 2, idx >> 16);
  67. bus_space_write_1(tuple->memt, tuple->memh,
  68. tuple->indirect_ptr + PCMCIA_INDR_ADDRESS + 3, idx >> 24);
  69. return bus_space_read_1(tuple->memt, tuple->memh,
  70. tuple->indirect_ptr + PCMCIA_INDR_DATA);
  71. } else
  72. return bus_space_read_1(tuple->memt, tuple->memh,
  73. idx << tuple->addrshift);
  74. }
  75. void
  76. pcmcia_read_cis(sc)
  77. struct pcmcia_softc *sc;
  78. {
  79. struct cis_state state;
  80. memset(&state, 0, sizeof state);
  81. state.card = &sc->card;
  82. state.card->error = 0;
  83. state.card->cis1_major = -1;
  84. state.card->cis1_minor = -1;
  85. state.card->cis1_info[0] = NULL;
  86. state.card->cis1_info[1] = NULL;
  87. state.card->cis1_info[2] = NULL;
  88. state.card->cis1_info[3] = NULL;
  89. state.card->manufacturer = PCMCIA_VENDOR_INVALID;
  90. state.card->product = PCMCIA_PRODUCT_INVALID;
  91. SIMPLEQ_INIT(&state.card->pf_head);
  92. state.pf = NULL;
  93. if (pcmcia_scan_cis((struct device *)sc, pcmcia_parse_cis_tuple,
  94. &state) == -1)
  95. state.card->error++;
  96. }
  97. int
  98. pcmcia_scan_cis(dev, fct, arg)
  99. struct device *dev;
  100. int (*fct)(struct pcmcia_tuple *, void *);
  101. void *arg;
  102. {
  103. struct pcmcia_softc *sc = (struct pcmcia_softc *) dev;
  104. pcmcia_chipset_tag_t pct;
  105. pcmcia_chipset_handle_t pch;
  106. int window;
  107. struct pcmcia_mem_handle pcmh;
  108. struct pcmcia_tuple tuple;
  109. int indirect_present;
  110. int longlink_present;
  111. int longlink_common;
  112. u_long longlink_addr;
  113. int mfc_count;
  114. int mfc_index;
  115. struct {
  116. int common;
  117. u_long addr;
  118. } mfc[256 / 5];
  119. int ret;
  120. ret = 0;
  121. pct = sc->pct;
  122. pch = sc->pch;
  123. /* allocate some memory */
  124. if (pcmcia_chip_mem_alloc(pct, pch, PCMCIA_CIS_SIZE, &pcmh)) {
  125. #ifdef DIAGNOSTIC
  126. printf("%s: can't alloc memory to read attributes\n",
  127. sc->dev.dv_xname);
  128. #endif
  129. return -1;
  130. }
  131. /* initialize state for the primary tuple chain */
  132. if (pcmcia_chip_mem_map(pct, pch, PCMCIA_MEM_ATTR, 0,
  133. PCMCIA_CIS_SIZE, &pcmh, &tuple.ptr, &window)) {
  134. pcmcia_chip_mem_free(pct, pch, &pcmh);
  135. #ifdef DIAGNOSTIC
  136. printf("%s: can't map memory to read attributes\n",
  137. sc->dev.dv_xname);
  138. #endif
  139. return -1;
  140. }
  141. tuple.memt = pcmh.memt;
  142. tuple.memh = pcmh.memh;
  143. DPRINTF(("cis mem map %x\n", (unsigned int) tuple.memh));
  144. tuple.addrshift = 1;
  145. tuple.flags = 0;
  146. indirect_present = 0;
  147. longlink_present = 1;
  148. longlink_common = 1;
  149. longlink_addr = 0;
  150. mfc_count = 0;
  151. mfc_index = 0;
  152. DPRINTF(("%s: CIS tuple chain:\n", sc->dev.dv_xname));
  153. while (1) {
  154. while (1) {
  155. /*
  156. * Perform boundary check for insane cards.
  157. * If CIS is too long, simulate CIS end.
  158. * (This check may not be sufficient for
  159. * malicious cards.)
  160. */
  161. if ((tuple.ptr << tuple.addrshift) >=
  162. PCMCIA_CIS_SIZE - 1 - 32 /* ad hoc value */) {
  163. DPRINTF(("CISTPL_END (too long CIS)\n"));
  164. tuple.code = PCMCIA_CISTPL_END;
  165. goto cis_end;
  166. }
  167. /* get the tuple code */
  168. tuple.code = pcmcia_cis_read_1(&tuple, tuple.ptr);
  169. /* two special-case tuples */
  170. if (tuple.code == PCMCIA_CISTPL_NULL) {
  171. DPRINTF(("CISTPL_NONE\n 00\n"));
  172. tuple.ptr++;
  173. continue;
  174. } else if (tuple.code == PCMCIA_CISTPL_END) {
  175. DPRINTF(("CISTPL_END\n ff\n"));
  176. cis_end:
  177. /* Call the function for the END tuple, since
  178. the CIS semantics depend on it */
  179. if ((*fct) (&tuple, arg)) {
  180. pcmcia_chip_mem_unmap(pct, pch,
  181. window);
  182. ret = 1;
  183. goto done;
  184. }
  185. tuple.ptr++;
  186. break;
  187. }
  188. /* now all the normal tuples */
  189. tuple.length = pcmcia_cis_read_1(&tuple, tuple.ptr + 1);
  190. switch (tuple.code) {
  191. case PCMCIA_CISTPL_INDIRECT:
  192. indirect_present = 1;
  193. DPRINTF(("CISTPL_INDIRECT\n"));
  194. break;
  195. case PCMCIA_CISTPL_LONGLINK_A:
  196. case PCMCIA_CISTPL_LONGLINK_C:
  197. if (tuple.length < 4) {
  198. DPRINTF(("CISTPL_LONGLINK_%s too "
  199. "short %d\n",
  200. longlink_common ? "C" : "A",
  201. tuple.length));
  202. break;
  203. }
  204. longlink_present = 1;
  205. longlink_common = (tuple.code ==
  206. PCMCIA_CISTPL_LONGLINK_C) ? 1 : 0;
  207. longlink_addr = pcmcia_tuple_read_4(&tuple, 0);
  208. DPRINTF(("CISTPL_LONGLINK_%s %lx\n",
  209. longlink_common ? "C" : "A",
  210. longlink_addr));
  211. break;
  212. case PCMCIA_CISTPL_NO_LINK:
  213. longlink_present = 0;
  214. DPRINTF(("CISTPL_NO_LINK\n"));
  215. break;
  216. case PCMCIA_CISTPL_CHECKSUM:
  217. if (tuple.length < 5) {
  218. DPRINTF(("CISTPL_CHECKSUM too "
  219. "short %d\n", tuple.length));
  220. break;
  221. } {
  222. int16_t offset;
  223. u_long addr, length;
  224. u_int cksum, sum;
  225. int i;
  226. *((u_int16_t *) & offset) =
  227. pcmcia_tuple_read_2(&tuple, 0);
  228. length = pcmcia_tuple_read_2(&tuple, 2);
  229. cksum = pcmcia_tuple_read_1(&tuple, 4);
  230. addr = tuple.ptr + offset;
  231. DPRINTF(("CISTPL_CHECKSUM addr=%lx "
  232. "len=%lx cksum=%x",
  233. addr, length, cksum));
  234. /*
  235. * XXX do more work to deal with
  236. * distant regions
  237. */
  238. if ((addr >= PCMCIA_CIS_SIZE) ||
  239. ((addr + length) >=
  240. PCMCIA_CIS_SIZE)) {
  241. DPRINTF((" skipped, "
  242. "too distant\n"));
  243. break;
  244. }
  245. sum = 0;
  246. for (i = 0; i < length; i++)
  247. sum += pcmcia_cis_read_1(&tuple,
  248. addr + i);
  249. if (cksum != (sum & 0xff)) {
  250. DPRINTF((" failed sum=%x\n",
  251. sum));
  252. printf("%s: CIS checksum "
  253. "failed\n",
  254. sc->dev.dv_xname);
  255. #if 0
  256. /*
  257. * XXX Some working cards have
  258. * XXX bad checksums!!
  259. */
  260. ret = -1;
  261. #endif
  262. } else {
  263. DPRINTF((" ok\n"));
  264. }
  265. }
  266. break;
  267. case PCMCIA_CISTPL_LONGLINK_MFC:
  268. if (tuple.length < 6) {
  269. DPRINTF(("CISTPL_LONGLINK_MFC too "
  270. "short %d\n", tuple.length));
  271. break;
  272. }
  273. if (((tuple.length - 1) % 5) != 0) {
  274. DPRINTF(("CISTPL_LONGLINK_MFC bogus "
  275. "length %d\n", tuple.length));
  276. break;
  277. }
  278. {
  279. int i, tmp_count;
  280. /*
  281. * put count into tmp var so that
  282. * if we have to bail (because it's
  283. * a bogus count) it won't be
  284. * remembered for later use.
  285. */
  286. tmp_count =
  287. pcmcia_tuple_read_1(&tuple, 0);
  288. DPRINTF(("CISTPL_LONGLINK_MFC %d",
  289. tmp_count));
  290. /*
  291. * make _sure_ it's the right size;
  292. * if too short, it may be a weird
  293. * (unknown/undefined) format
  294. */
  295. if (tuple.length != (tmp_count*5 + 1)) {
  296. DPRINTF((" bogus length %d\n",
  297. tuple.length));
  298. break;
  299. }
  300. #ifdef PCMCIACISDEBUG /* maybe enable all the time? */
  301. /*
  302. * sanity check for a programming
  303. * error which is difficult to find
  304. * when debugging.
  305. */
  306. if (tmp_count >
  307. howmany(sizeof mfc, sizeof mfc[0]))
  308. panic("CISTPL_LONGLINK_MFC mfc "
  309. "count would blow stack");
  310. #endif
  311. mfc_count = tmp_count;
  312. for (i = 0; i < mfc_count; i++) {
  313. mfc[i].common =
  314. (pcmcia_tuple_read_1(&tuple,
  315. 1 + 5 * i) ==
  316. PCMCIA_MFC_MEM_COMMON) ?
  317. 1 : 0;
  318. mfc[i].addr =
  319. pcmcia_tuple_read_4(&tuple,
  320. 1 + 5 * i + 1);
  321. DPRINTF((" %s:%lx",
  322. mfc[i].common ? "common" :
  323. "attr", mfc[i].addr));
  324. }
  325. DPRINTF(("\n"));
  326. }
  327. /*
  328. * for LONGLINK_MFC, fall through to the
  329. * function. This tuple has structural and
  330. * semantic content.
  331. */
  332. default:
  333. {
  334. if ((*fct) (&tuple, arg)) {
  335. pcmcia_chip_mem_unmap(pct,
  336. pch, window);
  337. ret = 1;
  338. goto done;
  339. }
  340. }
  341. break;
  342. } /* switch */
  343. #ifdef PCMCIACISDEBUG
  344. /* print the tuple */
  345. {
  346. int i;
  347. DPRINTF((" %02x %02x", tuple.code,
  348. tuple.length));
  349. for (i = 0; i < tuple.length; i++) {
  350. DPRINTF((" %02x",
  351. pcmcia_tuple_read_1(&tuple, i)));
  352. if ((i % 16) == 13)
  353. DPRINTF(("\n"));
  354. }
  355. if ((i % 16) != 14)
  356. DPRINTF(("\n"));
  357. }
  358. #endif
  359. /* skip to the next tuple */
  360. tuple.ptr += 2 + tuple.length;
  361. }
  362. /*
  363. * the chain is done. Clean up and move onto the next one,
  364. * if any. The loop is here in the case that there is an MFC
  365. * card with no longlink (which defaults to existing, == 0).
  366. * In general, this means that if one pointer fails, it will
  367. * try the next one, instead of just bailing.
  368. */
  369. while (1) {
  370. pcmcia_chip_mem_unmap(pct, pch, window);
  371. if (indirect_present) {
  372. /*
  373. * Indirect CIS data needs to be obtained
  374. * from specific registers accessible at
  375. * a fixed location in the common window,
  376. * but otherwise is similar to longlink
  377. * in attribute memory.
  378. */
  379. pcmcia_chip_mem_map(pct, pch, PCMCIA_MEM_COMMON,
  380. 0, PCMCIA_INDR_SIZE,
  381. &pcmh, &tuple.indirect_ptr, &window);
  382. DPRINTF(("cis mem map %x ind %x\n",
  383. (unsigned int) tuple.memh,
  384. (unsigned int) tuple.indirect_ptr));
  385. tuple.addrshift = 1;
  386. tuple.flags |= PTF_INDIRECT;
  387. tuple.ptr = 0;
  388. longlink_present = 0;
  389. indirect_present = 0;
  390. } else if (longlink_present) {
  391. /*
  392. * if the longlink is to attribute memory,
  393. * then it is unindexed. That is, if the
  394. * link value is 0x100, then the actual
  395. * memory address is 0x200. This means that
  396. * we need to multiply by 2 before calling
  397. * mem_map, and then divide the resulting ptr
  398. * by 2 after.
  399. */
  400. if (!longlink_common)
  401. longlink_addr *= 2;
  402. pcmcia_chip_mem_map(pct, pch, longlink_common ?
  403. PCMCIA_MEM_COMMON : PCMCIA_MEM_ATTR,
  404. longlink_addr, PCMCIA_CIS_SIZE,
  405. &pcmh, &tuple.ptr, &window);
  406. if (!longlink_common)
  407. tuple.ptr /= 2;
  408. DPRINTF(("cis mem map %x\n",
  409. (unsigned int) tuple.memh));
  410. tuple.addrshift = longlink_common ? 0 : 1;
  411. longlink_present = 0;
  412. longlink_common = 1;
  413. longlink_addr = 0;
  414. } else if (mfc_count && (mfc_index < mfc_count)) {
  415. if (!mfc[mfc_index].common)
  416. mfc[mfc_index].addr *= 2;
  417. pcmcia_chip_mem_map(pct, pch,
  418. mfc[mfc_index].common ?
  419. PCMCIA_MEM_COMMON : PCMCIA_MEM_ATTR,
  420. mfc[mfc_index].addr, PCMCIA_CIS_SIZE,
  421. &pcmh, &tuple.ptr, &window);
  422. if (!mfc[mfc_index].common)
  423. tuple.ptr /= 2;
  424. DPRINTF(("cis mem map %x\n",
  425. (unsigned int) tuple.memh));
  426. /* set parse state, and point at the next one */
  427. tuple.addrshift = mfc[mfc_index].common ? 0 : 1;
  428. mfc_index++;
  429. } else {
  430. goto done;
  431. }
  432. /* make sure that the link is valid */
  433. tuple.code = pcmcia_cis_read_1(&tuple, tuple.ptr);
  434. if (tuple.code != PCMCIA_CISTPL_LINKTARGET) {
  435. DPRINTF(("CISTPL_LINKTARGET expected, "
  436. "code %02x observed\n", tuple.code));
  437. continue;
  438. }
  439. tuple.length = pcmcia_cis_read_1(&tuple, tuple.ptr + 1);
  440. if (tuple.length < 3) {
  441. DPRINTF(("CISTPL_LINKTARGET too short %d\n",
  442. tuple.length));
  443. continue;
  444. }
  445. if ((pcmcia_tuple_read_1(&tuple, 0) != 'C') ||
  446. (pcmcia_tuple_read_1(&tuple, 1) != 'I') ||
  447. (pcmcia_tuple_read_1(&tuple, 2) != 'S')) {
  448. DPRINTF(("CISTPL_LINKTARGET magic "
  449. "%02x%02x%02x incorrect\n",
  450. pcmcia_tuple_read_1(&tuple, 0),
  451. pcmcia_tuple_read_1(&tuple, 1),
  452. pcmcia_tuple_read_1(&tuple, 2)));
  453. continue;
  454. }
  455. tuple.ptr += 2 + tuple.length;
  456. break;
  457. }
  458. }
  459. pcmcia_chip_mem_unmap(pct, pch, window);
  460. done:
  461. /* Last, free the allocated memory block */
  462. pcmcia_chip_mem_free(pct, pch, &pcmh);
  463. return (ret);
  464. }
  465. /* XXX this is incredibly verbose. Not sure what trt is */
  466. void
  467. pcmcia_print_cis(sc)
  468. struct pcmcia_softc *sc;
  469. {
  470. struct pcmcia_card *card = &sc->card;
  471. struct pcmcia_function *pf;
  472. struct pcmcia_config_entry *cfe;
  473. int i;
  474. printf("%s: CIS version ", sc->dev.dv_xname);
  475. if (card->cis1_major == 4) {
  476. if (card->cis1_minor == 0)
  477. printf("PCMCIA 1.0\n");
  478. else if (card->cis1_minor == 1)
  479. printf("PCMCIA 2.0 or 2.1\n");
  480. } else if (card->cis1_major >= 5)
  481. printf("PC Card Standard %d.%d\n", card->cis1_major,
  482. card->cis1_minor);
  483. else
  484. printf("unknown (major=%d, minor=%d)\n",
  485. card->cis1_major, card->cis1_minor);
  486. printf("%s: CIS info: ", sc->dev.dv_xname);
  487. for (i = 0; i < 4; i++) {
  488. if (card->cis1_info[i] == NULL)
  489. break;
  490. if (i)
  491. printf(", ");
  492. printf("%s", card->cis1_info[i]);
  493. }
  494. printf("\n");
  495. printf("%s: Manufacturer code 0x%x, product 0x%x\n",
  496. sc->dev.dv_xname, card->manufacturer, card->product);
  497. SIMPLEQ_FOREACH(pf, &card->pf_head, pf_list) {
  498. printf("%s: function %d: ", sc->dev.dv_xname, pf->number);
  499. switch (pf->function) {
  500. case PCMCIA_FUNCTION_UNSPEC:
  501. printf("unspecified");
  502. break;
  503. case PCMCIA_FUNCTION_MULTIFUNCTION:
  504. printf("multi-function");
  505. break;
  506. case PCMCIA_FUNCTION_MEMORY:
  507. printf("memory");
  508. break;
  509. case PCMCIA_FUNCTION_SERIAL:
  510. printf("serial port");
  511. break;
  512. case PCMCIA_FUNCTION_PARALLEL:
  513. printf("parallel port");
  514. break;
  515. case PCMCIA_FUNCTION_DISK:
  516. printf("fixed disk");
  517. break;
  518. case PCMCIA_FUNCTION_VIDEO:
  519. printf("video adapter");
  520. break;
  521. case PCMCIA_FUNCTION_NETWORK:
  522. printf("network adapter");
  523. break;
  524. case PCMCIA_FUNCTION_AIMS:
  525. printf("auto incrementing mass storage");
  526. break;
  527. case PCMCIA_FUNCTION_SCSI:
  528. printf("SCSI bridge");
  529. break;
  530. case PCMCIA_FUNCTION_SECURITY:
  531. printf("Security services");
  532. break;
  533. case PCMCIA_FUNCTION_INSTRUMENT:
  534. printf("Instrument");
  535. break;
  536. case PCMCIA_FUNCTION_IOBUS:
  537. printf("Serial I/O Bus Adapter");
  538. break;
  539. default:
  540. printf("unknown (%d)", pf->function);
  541. break;
  542. }
  543. printf(", ccr addr %lx mask %lx\n", pf->ccr_base, pf->ccr_mask);
  544. SIMPLEQ_FOREACH(cfe, &pf->cfe_head, cfe_list) {
  545. printf("%s: function %d, config table entry %d: ",
  546. sc->dev.dv_xname, pf->number, cfe->number);
  547. switch (cfe->iftype) {
  548. case PCMCIA_IFTYPE_MEMORY:
  549. printf("memory card");
  550. break;
  551. case PCMCIA_IFTYPE_IO:
  552. printf("I/O card");
  553. break;
  554. default:
  555. printf("card type unknown");
  556. break;
  557. }
  558. printf("; irq mask %x", cfe->irqmask);
  559. if (cfe->num_iospace) {
  560. printf("; iomask %lx, iospace", cfe->iomask);
  561. for (i = 0; i < cfe->num_iospace; i++)
  562. printf(" %lx%s%lx",
  563. cfe->iospace[i].start,
  564. cfe->iospace[i].length ? "-" : "",
  565. cfe->iospace[i].start +
  566. cfe->iospace[i].length - 1);
  567. }
  568. if (cfe->num_memspace) {
  569. printf("; memspace");
  570. for (i = 0; i < cfe->num_memspace; i++)
  571. printf(" %lx%s%lx%s%lx",
  572. cfe->memspace[i].cardaddr,
  573. cfe->memspace[i].length ? "-" : "",
  574. cfe->memspace[i].cardaddr +
  575. cfe->memspace[i].length - 1,
  576. cfe->memspace[i].hostaddr ?
  577. "@" : "",
  578. cfe->memspace[i].hostaddr);
  579. }
  580. if (cfe->maxtwins)
  581. printf("; maxtwins %d", cfe->maxtwins);
  582. printf(";");
  583. if (cfe->flags & PCMCIA_CFE_MWAIT_REQUIRED)
  584. printf(" mwait_required");
  585. if (cfe->flags & PCMCIA_CFE_RDYBSY_ACTIVE)
  586. printf(" rdybsy_active");
  587. if (cfe->flags & PCMCIA_CFE_WP_ACTIVE)
  588. printf(" wp_active");
  589. if (cfe->flags & PCMCIA_CFE_BVD_ACTIVE)
  590. printf(" bvd_active");
  591. if (cfe->flags & PCMCIA_CFE_IO8)
  592. printf(" io8");
  593. if (cfe->flags & PCMCIA_CFE_IO16)
  594. printf(" io16");
  595. if (cfe->flags & PCMCIA_CFE_IRQSHARE)
  596. printf(" irqshare");
  597. if (cfe->flags & PCMCIA_CFE_IRQPULSE)
  598. printf(" irqpulse");
  599. if (cfe->flags & PCMCIA_CFE_IRQLEVEL)
  600. printf(" irqlevel");
  601. if (cfe->flags & PCMCIA_CFE_POWERDOWN)
  602. printf(" powerdown");
  603. if (cfe->flags & PCMCIA_CFE_READONLY)
  604. printf(" readonly");
  605. if (cfe->flags & PCMCIA_CFE_AUDIO)
  606. printf(" audio");
  607. printf("\n");
  608. }
  609. }
  610. if (card->error)
  611. printf("%s: %d errors found while parsing CIS\n",
  612. sc->dev.dv_xname, card->error);
  613. }
  614. int
  615. pcmcia_parse_cis_tuple(tuple, arg)
  616. struct pcmcia_tuple *tuple;
  617. void *arg;
  618. {
  619. /* most of these are educated guesses */
  620. static struct pcmcia_config_entry init_cfe = {
  621. -1, PCMCIA_CFE_RDYBSY_ACTIVE | PCMCIA_CFE_WP_ACTIVE |
  622. PCMCIA_CFE_BVD_ACTIVE, PCMCIA_IFTYPE_MEMORY,
  623. };
  624. struct cis_state *state = arg;
  625. switch (tuple->code) {
  626. case PCMCIA_CISTPL_END:
  627. /*
  628. * If we've seen a LONGLINK_MFC, and this is the first
  629. * END after it, reset the function list.
  630. *
  631. * XXX This might also be the right place to start a
  632. * new function, but that assumes that a function
  633. * definition never crosses any longlink, and I'm not
  634. * sure about that. This is probably safe for MFC
  635. * cards, but what we have now isn't broken, so I'd
  636. * rather not change it.
  637. */
  638. if (state->gotmfc == 1) {
  639. struct pcmcia_function *pf, *pfnext;
  640. for (pf = SIMPLEQ_FIRST(&state->card->pf_head);
  641. pf != NULL; pf = pfnext) {
  642. pfnext = SIMPLEQ_NEXT(pf, pf_list);
  643. free(pf, M_DEVBUF, 0);
  644. }
  645. SIMPLEQ_INIT(&state->card->pf_head);
  646. state->count = 0;
  647. state->gotmfc = 2;
  648. state->pf = NULL;
  649. }
  650. break;
  651. case PCMCIA_CISTPL_LONGLINK_MFC:
  652. /*
  653. * This tuple's structure was dealt with in scan_cis. here,
  654. * record the fact that the MFC tuple was seen, so that
  655. * functions declared before the MFC link can be cleaned
  656. * up.
  657. */
  658. state->gotmfc = 1;
  659. break;
  660. #ifdef PCMCIACISDEBUG
  661. case PCMCIA_CISTPL_DEVICE:
  662. case PCMCIA_CISTPL_DEVICE_A:
  663. {
  664. u_int reg, dtype, dspeed;
  665. reg = pcmcia_tuple_read_1(tuple, 0);
  666. dtype = reg & PCMCIA_DTYPE_MASK;
  667. dspeed = reg & PCMCIA_DSPEED_MASK;
  668. DPRINTF(("CISTPL_DEVICE%s type=",
  669. (tuple->code == PCMCIA_CISTPL_DEVICE) ? "" : "_A"));
  670. switch (dtype) {
  671. case PCMCIA_DTYPE_NULL:
  672. DPRINTF(("null"));
  673. break;
  674. case PCMCIA_DTYPE_ROM:
  675. DPRINTF(("rom"));
  676. break;
  677. case PCMCIA_DTYPE_OTPROM:
  678. DPRINTF(("otprom"));
  679. break;
  680. case PCMCIA_DTYPE_EPROM:
  681. DPRINTF(("eprom"));
  682. break;
  683. case PCMCIA_DTYPE_EEPROM:
  684. DPRINTF(("eeprom"));
  685. break;
  686. case PCMCIA_DTYPE_FLASH:
  687. DPRINTF(("flash"));
  688. break;
  689. case PCMCIA_DTYPE_SRAM:
  690. DPRINTF(("sram"));
  691. break;
  692. case PCMCIA_DTYPE_DRAM:
  693. DPRINTF(("dram"));
  694. break;
  695. case PCMCIA_DTYPE_FUNCSPEC:
  696. DPRINTF(("funcspec"));
  697. break;
  698. case PCMCIA_DTYPE_EXTEND:
  699. DPRINTF(("extend"));
  700. break;
  701. default:
  702. DPRINTF(("reserved"));
  703. break;
  704. }
  705. DPRINTF((" speed="));
  706. switch (dspeed) {
  707. case PCMCIA_DSPEED_NULL:
  708. DPRINTF(("null"));
  709. break;
  710. case PCMCIA_DSPEED_250NS:
  711. DPRINTF(("250ns"));
  712. break;
  713. case PCMCIA_DSPEED_200NS:
  714. DPRINTF(("200ns"));
  715. break;
  716. case PCMCIA_DSPEED_150NS:
  717. DPRINTF(("150ns"));
  718. break;
  719. case PCMCIA_DSPEED_100NS:
  720. DPRINTF(("100ns"));
  721. break;
  722. case PCMCIA_DSPEED_EXT:
  723. DPRINTF(("ext"));
  724. break;
  725. default:
  726. DPRINTF(("reserved"));
  727. break;
  728. }
  729. }
  730. DPRINTF(("\n"));
  731. break;
  732. #endif
  733. case PCMCIA_CISTPL_VERS_1:
  734. if (tuple->length < 6) {
  735. DPRINTF(("CISTPL_VERS_1 too short %d\n",
  736. tuple->length));
  737. break;
  738. } {
  739. int start, i, ch, count;
  740. state->card->cis1_major = pcmcia_tuple_read_1(tuple, 0);
  741. state->card->cis1_minor = pcmcia_tuple_read_1(tuple, 1);
  742. for (count = 0, start = 0, i = 0;
  743. (count < 4) && ((i + 4) < 256); i++) {
  744. ch = pcmcia_tuple_read_1(tuple, 2 + i);
  745. if (ch == 0xff)
  746. break;
  747. state->card->cis1_info_buf[i] = ch;
  748. if (ch == 0) {
  749. state->card->cis1_info[count] =
  750. state->card->cis1_info_buf + start;
  751. start = i + 1;
  752. count++;
  753. }
  754. }
  755. DPRINTF(("CISTPL_VERS_1\n"));
  756. }
  757. break;
  758. case PCMCIA_CISTPL_MANFID:
  759. if (tuple->length < 4) {
  760. DPRINTF(("CISTPL_MANFID too short %d\n",
  761. tuple->length));
  762. break;
  763. }
  764. state->card->manufacturer = pcmcia_tuple_read_2(tuple, 0);
  765. state->card->product = pcmcia_tuple_read_2(tuple, 2);
  766. DPRINTF(("CISTPL_MANFID\n"));
  767. break;
  768. case PCMCIA_CISTPL_FUNCID:
  769. if (tuple->length < 2) {
  770. DPRINTF(("CISTPL_FUNCID too short %d\n",
  771. tuple->length));
  772. break;
  773. }
  774. /*
  775. * As far as I understand this, manufacturers do multifunction
  776. * cards in various ways. Sadly enough I do not have the
  777. * PC-Card standard (donate!) so I can only guess what can
  778. * be done.
  779. * The original code implies FUNCID nodes are above CONFIG
  780. * nodes in the CIS tree, however Xircom does it the other
  781. * way round, which of course makes things a bit hard.
  782. * --niklas@openbsd.org
  783. */
  784. if (state->pf) {
  785. if (state->pf->function == PCMCIA_FUNCTION_UNSPEC) {
  786. /*
  787. * This looks like a opportunistic function
  788. * created by a CONFIG tuple. Just keep it.
  789. */
  790. } else {
  791. /*
  792. * A function is being defined, end it.
  793. */
  794. state->pf = NULL;
  795. }
  796. }
  797. if (state->pf == NULL) {
  798. state->pf = malloc(sizeof(*state->pf), M_DEVBUF,
  799. M_NOWAIT | M_ZERO);
  800. if (state->pf == NULL)
  801. panic("pcmcia_parse_cis_tuple");
  802. state->pf->number = state->count++;
  803. state->pf->last_config_index = -1;
  804. SIMPLEQ_INIT(&state->pf->cfe_head);
  805. SIMPLEQ_INSERT_TAIL(&state->card->pf_head, state->pf,
  806. pf_list);
  807. }
  808. state->pf->function = pcmcia_tuple_read_1(tuple, 0);
  809. DPRINTF(("CISTPL_FUNCID\n"));
  810. break;
  811. case PCMCIA_CISTPL_CONFIG:
  812. if (tuple->length < 3) {
  813. DPRINTF(("CISTPL_CONFIG too short %d\n",
  814. tuple->length));
  815. break;
  816. } {
  817. u_int reg, rasz, rmsz, rfsz;
  818. int i;
  819. reg = pcmcia_tuple_read_1(tuple, 0);
  820. rasz = 1 + ((reg & PCMCIA_TPCC_RASZ_MASK) >>
  821. PCMCIA_TPCC_RASZ_SHIFT);
  822. rmsz = 1 + ((reg & PCMCIA_TPCC_RMSZ_MASK) >>
  823. PCMCIA_TPCC_RMSZ_SHIFT);
  824. rfsz = ((reg & PCMCIA_TPCC_RFSZ_MASK) >>
  825. PCMCIA_TPCC_RFSZ_SHIFT);
  826. if (tuple->length < 2 + rasz + rmsz + rfsz) {
  827. DPRINTF(("CISTPL_CONFIG (%d,%d,%d) too "
  828. "short %d\n", rasz, rmsz, rfsz,
  829. tuple->length));
  830. break;
  831. }
  832. if (state->pf == NULL) {
  833. state->pf = malloc(sizeof(*state->pf),
  834. M_DEVBUF, M_NOWAIT | M_ZERO);
  835. if (state->pf == NULL)
  836. panic("pcmcia_parse_cis_tuple");
  837. state->pf->number = state->count++;
  838. state->pf->last_config_index = -1;
  839. SIMPLEQ_INIT(&state->pf->cfe_head);
  840. SIMPLEQ_INSERT_TAIL(&state->card->pf_head,
  841. state->pf, pf_list);
  842. state->pf->function = PCMCIA_FUNCTION_UNSPEC;
  843. }
  844. state->pf->last_config_index =
  845. pcmcia_tuple_read_1(tuple, 1);
  846. state->pf->ccr_base = 0;
  847. for (i = 0; i < rasz; i++)
  848. state->pf->ccr_base |=
  849. ((pcmcia_tuple_read_1(tuple, 2 + i)) <<
  850. (i * 8));
  851. state->pf->ccr_mask = 0;
  852. for (i = 0; i < rmsz; i++)
  853. state->pf->ccr_mask |=
  854. ((pcmcia_tuple_read_1(tuple,
  855. 2 + rasz + i)) << (i * 8));
  856. /* skip the reserved area and subtuples */
  857. /* reset the default cfe for each cfe list */
  858. state->temp_cfe = init_cfe;
  859. state->default_cfe = &state->temp_cfe;
  860. }
  861. DPRINTF(("CISTPL_CONFIG\n"));
  862. break;
  863. case PCMCIA_CISTPL_CFTABLE_ENTRY:
  864. if (tuple->length < 2) {
  865. DPRINTF(("CISTPL_CFTABLE_ENTRY too short %d\n",
  866. tuple->length));
  867. break;
  868. } {
  869. int idx, i, j;
  870. u_int reg, reg2;
  871. u_int intface, def, num;
  872. u_int power, timing, iospace, irq, memspace, misc;
  873. struct pcmcia_config_entry *cfe;
  874. idx = 0;
  875. reg = pcmcia_tuple_read_1(tuple, idx);
  876. idx++;
  877. intface = reg & PCMCIA_TPCE_INDX_INTFACE;
  878. def = reg & PCMCIA_TPCE_INDX_DEFAULT;
  879. num = reg & PCMCIA_TPCE_INDX_NUM_MASK;
  880. /*
  881. * this is a little messy. Some cards have only a
  882. * cfentry with the default bit set. So, as we go
  883. * through the list, we add new indexes to the queue,
  884. * and keep a pointer to the last one with the
  885. * default bit set. if we see a record with the same
  886. * index, as the default, we stash the default and
  887. * replace the queue entry. otherwise, we just add
  888. * new entries to the queue, pointing the default ptr
  889. * at them if the default bit is set. if we get to
  890. * the end with the default pointer pointing at a
  891. * record which hasn't had a matching index, that's
  892. * ok; it just becomes a cfentry like any other.
  893. */
  894. /*
  895. * if the index in the cis differs from the default
  896. * cis, create new entry in the queue and start it
  897. * with the current default
  898. */
  899. if (state->default_cfe == NULL) {
  900. DPRINTF(("CISTPL_CFTABLE_ENTRY with no "
  901. "default\n"));
  902. break;
  903. }
  904. if (num != state->default_cfe->number) {
  905. cfe = (struct pcmcia_config_entry *)
  906. malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT);
  907. if (cfe == NULL)
  908. panic("pcmcia_parse_cis_tuple");
  909. *cfe = *state->default_cfe;
  910. SIMPLEQ_INSERT_TAIL(&state->pf->cfe_head,
  911. cfe, cfe_list);
  912. cfe->number = num;
  913. /*
  914. * if the default bit is set in the cis, then
  915. * point the new default at whatever is being
  916. * filled in
  917. */
  918. if (def)
  919. state->default_cfe = cfe;
  920. } else {
  921. /*
  922. * the cis index matches the default index,
  923. * fill in the default cfentry. It is
  924. * assumed that the cfdefault index is in the
  925. * queue. For it to be otherwise, the cis
  926. * index would have to be -1 (initial
  927. * condition) which is not possible, or there
  928. * would have to be a preceding cis entry
  929. * which had the same cis index and had the
  930. * default bit unset. Neither condition
  931. * should happen. If it does, this cfentry
  932. * is lost (written into temp space), which
  933. * is an acceptable failure mode.
  934. */
  935. cfe = state->default_cfe;
  936. /*
  937. * if the cis entry does not have the default
  938. * bit set, copy the default out of the way
  939. * first.
  940. */
  941. if (!def) {
  942. state->temp_cfe = *state->default_cfe;
  943. state->default_cfe = &state->temp_cfe;
  944. }
  945. }
  946. if (intface) {
  947. reg = pcmcia_tuple_read_1(tuple, idx);
  948. idx++;
  949. cfe->flags &= ~(PCMCIA_CFE_MWAIT_REQUIRED
  950. | PCMCIA_CFE_RDYBSY_ACTIVE
  951. | PCMCIA_CFE_WP_ACTIVE
  952. | PCMCIA_CFE_BVD_ACTIVE);
  953. if (reg & PCMCIA_TPCE_IF_MWAIT)
  954. cfe->flags |= PCMCIA_CFE_MWAIT_REQUIRED;
  955. if (reg & PCMCIA_TPCE_IF_RDYBSY)
  956. cfe->flags |= PCMCIA_CFE_RDYBSY_ACTIVE;
  957. if (reg & PCMCIA_TPCE_IF_WP)
  958. cfe->flags |= PCMCIA_CFE_WP_ACTIVE;
  959. if (reg & PCMCIA_TPCE_IF_BVD)
  960. cfe->flags |= PCMCIA_CFE_BVD_ACTIVE;
  961. cfe->iftype = reg & PCMCIA_TPCE_IF_IFTYPE;
  962. }
  963. reg = pcmcia_tuple_read_1(tuple, idx);
  964. idx++;
  965. power = reg & PCMCIA_TPCE_FS_POWER_MASK;
  966. timing = reg & PCMCIA_TPCE_FS_TIMING;
  967. iospace = reg & PCMCIA_TPCE_FS_IOSPACE;
  968. irq = reg & PCMCIA_TPCE_FS_IRQ;
  969. memspace = reg & PCMCIA_TPCE_FS_MEMSPACE_MASK;
  970. misc = reg & PCMCIA_TPCE_FS_MISC;
  971. if (power) {
  972. /* skip over power, don't save */
  973. /* for each parameter selection byte */
  974. for (i = 0; i < power; i++) {
  975. reg = pcmcia_tuple_read_1(tuple, idx);
  976. idx++;
  977. /* for each bit */
  978. for (j = 0; j < 7; j++) {
  979. /* if the bit is set */
  980. if ((reg >> j) & 0x01) {
  981. /* skip over bytes */
  982. do {
  983. reg2 = pcmcia_tuple_read_1(tuple, idx);
  984. idx++;
  985. /*
  986. * until
  987. * non-
  988. * extension
  989. * byte
  990. */
  991. } while (reg2 & 0x80);
  992. }
  993. }
  994. }
  995. }
  996. if (timing) {
  997. /* skip over timing, don't save */
  998. reg = pcmcia_tuple_read_1(tuple, idx);
  999. idx++;
  1000. if ((reg & PCMCIA_TPCE_TD_RESERVED_MASK) !=
  1001. PCMCIA_TPCE_TD_RESERVED_MASK)
  1002. idx++;
  1003. if ((reg & PCMCIA_TPCE_TD_RDYBSY_MASK) !=
  1004. PCMCIA_TPCE_TD_RDYBSY_MASK)
  1005. idx++;
  1006. if ((reg & PCMCIA_TPCE_TD_WAIT_MASK) !=
  1007. PCMCIA_TPCE_TD_WAIT_MASK)
  1008. idx++;
  1009. }
  1010. if (iospace) {
  1011. if (tuple->length <= idx) {
  1012. DPRINTF(("ran out of space before TPCE_IO\n"));
  1013. goto abort_cfe;
  1014. }
  1015. reg = pcmcia_tuple_read_1(tuple, idx);
  1016. idx++;
  1017. cfe->flags &=
  1018. ~(PCMCIA_CFE_IO8 | PCMCIA_CFE_IO16);
  1019. if (reg & PCMCIA_TPCE_IO_BUSWIDTH_8BIT)
  1020. cfe->flags |= PCMCIA_CFE_IO8;
  1021. if (reg & PCMCIA_TPCE_IO_BUSWIDTH_16BIT)
  1022. cfe->flags |= PCMCIA_CFE_IO16;
  1023. cfe->iomask =
  1024. reg & PCMCIA_TPCE_IO_IOADDRLINES_MASK;
  1025. if (reg & PCMCIA_TPCE_IO_HASRANGE) {
  1026. reg = pcmcia_tuple_read_1(tuple, idx);
  1027. idx++;
  1028. cfe->num_iospace = 1 + (reg &
  1029. PCMCIA_TPCE_IO_RANGE_COUNT);
  1030. if (cfe->num_iospace >
  1031. (sizeof(cfe->iospace) /
  1032. sizeof(cfe->iospace[0]))) {
  1033. DPRINTF(("too many io "
  1034. "spaces %d",
  1035. cfe->num_iospace));
  1036. state->card->error++;
  1037. break;
  1038. }
  1039. for (i = 0; i < cfe->num_iospace; i++) {
  1040. switch (reg & PCMCIA_TPCE_IO_RANGE_ADDRSIZE_MASK) {
  1041. case PCMCIA_TPCE_IO_RANGE_ADDRSIZE_ONE:
  1042. cfe->iospace[i].start =
  1043. pcmcia_tuple_read_1(tuple, idx);
  1044. idx++;
  1045. break;
  1046. case PCMCIA_TPCE_IO_RANGE_ADDRSIZE_TWO:
  1047. cfe->iospace[i].start =
  1048. pcmcia_tuple_read_2(tuple, idx);
  1049. idx += 2;
  1050. break;
  1051. case PCMCIA_TPCE_IO_RANGE_ADDRSIZE_FOUR:
  1052. cfe->iospace[i].start =
  1053. pcmcia_tuple_read_4(tuple, idx);
  1054. idx += 4;
  1055. break;
  1056. }
  1057. switch (reg &
  1058. PCMCIA_TPCE_IO_RANGE_LENGTHSIZE_MASK) {
  1059. case PCMCIA_TPCE_IO_RANGE_LENGTHSIZE_ONE:
  1060. cfe->iospace[i].length =
  1061. pcmcia_tuple_read_1(tuple, idx);
  1062. idx++;
  1063. break;
  1064. case PCMCIA_TPCE_IO_RANGE_LENGTHSIZE_TWO:
  1065. cfe->iospace[i].length =
  1066. pcmcia_tuple_read_2(tuple, idx);
  1067. idx += 2;
  1068. break;
  1069. case PCMCIA_TPCE_IO_RANGE_LENGTHSIZE_FOUR:
  1070. cfe->iospace[i].length =
  1071. pcmcia_tuple_read_4(tuple, idx);
  1072. idx += 4;
  1073. break;
  1074. }
  1075. cfe->iospace[i].length++;
  1076. }
  1077. } else {
  1078. cfe->num_iospace = 1;
  1079. cfe->iospace[0].start = 0;
  1080. cfe->iospace[0].length =
  1081. (1 << cfe->iomask);
  1082. }
  1083. }
  1084. if (irq) {
  1085. if (tuple->length <= idx) {
  1086. DPRINTF(("ran out of space before TPCE_IR\n"));
  1087. goto abort_cfe;
  1088. }
  1089. reg = pcmcia_tuple_read_1(tuple, idx);
  1090. idx++;
  1091. cfe->flags &= ~(PCMCIA_CFE_IRQSHARE
  1092. | PCMCIA_CFE_IRQPULSE
  1093. | PCMCIA_CFE_IRQLEVEL);
  1094. if (reg & PCMCIA_TPCE_IR_SHARE)
  1095. cfe->flags |= PCMCIA_CFE_IRQSHARE;
  1096. if (reg & PCMCIA_TPCE_IR_PULSE)
  1097. cfe->flags |= PCMCIA_CFE_IRQPULSE;
  1098. if (reg & PCMCIA_TPCE_IR_LEVEL)
  1099. cfe->flags |= PCMCIA_CFE_IRQLEVEL;
  1100. if (reg & PCMCIA_TPCE_IR_HASMASK) {
  1101. /*
  1102. * it's legal to ignore the
  1103. * special-interrupt bits, so I will
  1104. */
  1105. cfe->irqmask =
  1106. pcmcia_tuple_read_2(tuple, idx);
  1107. idx += 2;
  1108. } else {
  1109. cfe->irqmask =
  1110. (1 << (reg & PCMCIA_TPCE_IR_IRQ));
  1111. }
  1112. }
  1113. if (memspace) {
  1114. if (tuple->length <= idx) {
  1115. DPRINTF(("ran out of space before TPCE_MS\n"));
  1116. goto abort_cfe;
  1117. }
  1118. if (memspace == PCMCIA_TPCE_FS_MEMSPACE_NONE) {
  1119. cfe->num_memspace = 0;
  1120. } else if (memspace == PCMCIA_TPCE_FS_MEMSPACE_LENGTH) {
  1121. cfe->num_memspace = 1;
  1122. cfe->memspace[0].length = 256 *
  1123. pcmcia_tuple_read_2(tuple, idx);
  1124. idx += 2;
  1125. cfe->memspace[0].cardaddr = 0;
  1126. cfe->memspace[0].hostaddr = 0;
  1127. } else if (memspace ==
  1128. PCMCIA_TPCE_FS_MEMSPACE_LENGTHADDR) {
  1129. cfe->num_memspace = 1;
  1130. cfe->memspace[0].length = 256 *
  1131. pcmcia_tuple_read_2(tuple, idx);
  1132. idx += 2;
  1133. cfe->memspace[0].cardaddr = 256 *
  1134. pcmcia_tuple_read_2(tuple, idx);
  1135. idx += 2;
  1136. cfe->memspace[0].hostaddr = cfe->memspace[0].cardaddr;
  1137. } else {
  1138. int lengthsize;
  1139. int cardaddrsize;
  1140. int hostaddrsize;
  1141. reg = pcmcia_tuple_read_1(tuple, idx);
  1142. idx++;
  1143. cfe->num_memspace = (reg &
  1144. PCMCIA_TPCE_MS_COUNT) + 1;
  1145. if (cfe->num_memspace >
  1146. (sizeof(cfe->memspace) /
  1147. sizeof(cfe->memspace[0]))) {
  1148. DPRINTF(("too many mem "
  1149. "spaces %d",
  1150. cfe->num_memspace));
  1151. state->card->error++;
  1152. break;
  1153. }
  1154. lengthsize =
  1155. ((reg & PCMCIA_TPCE_MS_LENGTH_SIZE_MASK) >>
  1156. PCMCIA_TPCE_MS_LENGTH_SIZE_SHIFT);
  1157. cardaddrsize =
  1158. ((reg & PCMCIA_TPCE_MS_CARDADDR_SIZE_MASK) >>
  1159. PCMCIA_TPCE_MS_CARDADDR_SIZE_SHIFT);
  1160. hostaddrsize =
  1161. (reg & PCMCIA_TPCE_MS_HOSTADDR) ? cardaddrsize : 0;
  1162. if (lengthsize == 0) {
  1163. DPRINTF(("cfe memspace "
  1164. "lengthsize == 0"));
  1165. state->card->error++;
  1166. }
  1167. for (i = 0; i < cfe->num_memspace; i++) {
  1168. if (lengthsize) {
  1169. cfe->memspace[i].length =
  1170. 256 * pcmcia_tuple_read_n(tuple, lengthsize,
  1171. idx);
  1172. idx += lengthsize;
  1173. } else {
  1174. cfe->memspace[i].length = 0;
  1175. }
  1176. if (cfe->memspace[i].length == 0) {
  1177. DPRINTF(("cfe->memspace[%d].length == 0",
  1178. i));
  1179. state->card->error++;
  1180. }
  1181. if (cardaddrsize) {
  1182. cfe->memspace[i].cardaddr =
  1183. 256 * pcmcia_tuple_read_n(tuple, cardaddrsize,
  1184. idx);
  1185. idx += cardaddrsize;
  1186. } else {
  1187. cfe->memspace[i].cardaddr = 0;
  1188. }
  1189. if (hostaddrsize) {
  1190. cfe->memspace[i].hostaddr =
  1191. 256 * pcmcia_tuple_read_n(tuple, hostaddrsize,
  1192. idx);
  1193. idx += hostaddrsize;
  1194. } else {
  1195. cfe->memspace[i].hostaddr = 0;
  1196. }
  1197. }
  1198. }
  1199. }
  1200. if (misc) {
  1201. if (tuple->length <= idx) {
  1202. DPRINTF(("ran out of space before TPCE_MI\n"));
  1203. goto abort_cfe;
  1204. }
  1205. reg = pcmcia_tuple_read_1(tuple, idx);
  1206. idx++;
  1207. cfe->flags &= ~(PCMCIA_CFE_POWERDOWN
  1208. | PCMCIA_CFE_READONLY
  1209. | PCMCIA_CFE_AUDIO);
  1210. if (reg & PCMCIA_TPCE_MI_PWRDOWN)
  1211. cfe->flags |= PCMCIA_CFE_POWERDOWN;
  1212. if (reg & PCMCIA_TPCE_MI_READONLY)
  1213. cfe->flags |= PCMCIA_CFE_READONLY;
  1214. if (reg & PCMCIA_TPCE_MI_AUDIO)
  1215. cfe->flags |= PCMCIA_CFE_AUDIO;
  1216. cfe->maxtwins = reg & PCMCIA_TPCE_MI_MAXTWINS;
  1217. while (reg & PCMCIA_TPCE_MI_EXT) {
  1218. reg = pcmcia_tuple_read_1(tuple, idx);
  1219. idx++;
  1220. }
  1221. }
  1222. /* skip all the subtuples */
  1223. }
  1224. abort_cfe:
  1225. DPRINTF(("CISTPL_CFTABLE_ENTRY\n"));
  1226. break;
  1227. default:
  1228. DPRINTF(("unhandled CISTPL %x\n", tuple->code));
  1229. break;
  1230. }
  1231. return (0);
  1232. }