15 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/string.h>
20 #include <linux/errno.h>
22 #include <linux/slab.h>
24 #include <linux/pci.h>
27 #include <asm/byteorder.h>
28 #include <asm/unaligned.h>
35 static const u_char mantissa[] = {
36 10, 12, 13, 15, 20, 25, 30, 35,
37 40, 45, 50, 55, 60, 70, 80, 90
41 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000
45 #define SPEED_CVT(v) \
46 (mantissa[(((v)>>3)&15)-1] * exponent[(v)&7] / 10)
48 #define POWER_CVT(v) \
49 (mantissa[((v)>>3)&15] * exponent[(v)&7] / 10)
50 #define POWER_SCALE(v) (exponent[(v)&7])
53 #define MAX_TUPLES 200
56 #define IRQ_INFO2_VALID 0x10
88 unsigned int card_offset,
unsigned int flags)
98 "cs: unable to map card memory!\n");
110 ret = s->
ops->set_mem_map(s, mem);
129 #define IS_INDIRECT 8
142 dev_dbg(&s->
dev,
"pcmcia_read_cis_mem(%d, %#x, %u)\n", attr, addr, len);
166 for ( ; len > 0; len--, buf++)
173 "attempt to read CIS mem at addr %#x", addr);
182 card_offset = addr & ~(s->
map_size-1);
184 sys = set_cis_map(s, card_offset, flags);
191 sys = sys + (addr & (s->
map_size-1));
192 for ( ; len > 0; len--, buf++, sys +=
inc) {
201 dev_dbg(&s->
dev,
" %#2.2x %#2.2x %#2.2x %#2.2x ...\n",
221 "pcmcia_write_cis_mem(%d, %#x, %u)\n", attr, addr, len);
244 for ( ; len > 0; len--, buf++)
256 card_offset = addr & ~(s->
map_size-1);
258 sys = set_cis_map(s, card_offset, flags);
265 sys = sys + (addr & (s->
map_size-1));
266 for ( ; len > 0; len--, buf++, sys +=
inc) {
287 size_t len,
void *
ptr)
308 if (cis->
addr == addr && cis->
len == len && cis->
attr == attr) {
340 if (cis->addr == addr && cis->len == len && cis->attr == attr) {
382 "no memory for verifying CIS\n");
411 const u8 *
data,
const size_t len)
441 #define LINK_SPACE(f) (((tuple_flags *)(&(f)))->link_space)
442 #define HAS_LINK(f) (((tuple_flags *)(&(f)))->has_link)
443 #define MFC_FN(f) (((tuple_flags *)(&(f)))->mfc_fn)
444 #define SPACE(f) (((tuple_flags *)(&(f)))->space)
501 ret = read_cis_cache(s,
SPACE(tuple->
Flags), ofs, 5, link);
505 (
strncmp(link+2,
"CIS", 3) == 0))
507 remove_cis_cache(s,
SPACE(tuple->
Flags), ofs, 5);
511 ret = read_cis_cache(s,
SPACE(tuple->
Flags), ofs, 5, link);
515 (
strncmp(link+2,
"CIS", 3) == 0))
517 remove_cis_cache(s,
SPACE(tuple->
Flags), ofs, 5);
541 ret = read_cis_cache(s, attr, ofs, 2, link);
552 ofs = follow_link(s, tuple);
556 ret = read_cis_cache(s, attr, ofs, 2, link);
572 ret = read_cis_cache(s, attr, ofs+2, 4,
580 ret = read_cis_cache(s, attr, ofs+2, 4,
596 ret = read_cis_cache(s, attr, ofs+2,
622 if (i == MAX_TUPLES) {
623 dev_dbg(&s->
dev,
"cs: overrun in pcmcia_get_next_tuple\n");
673 device->
dev[
i].type = (*p >> 4);
674 device->
dev[
i].wp = (*p & 0x08) ? 1 : 0;
677 device->
dev[
i].speed = 0;
680 device->
dev[
i].speed = 250;
683 device->
dev[
i].speed = 200;
686 device->
dev[
i].speed = 150;
689 device->
dev[
i].speed = 100;
710 device->
dev[
i].size = ((*p >> 3) + 1) * (512 << (scale*2));
727 csum->
len = get_unaligned_le16(p + 2);
728 csum->
sum = *(p + 4);
752 for (i = 0; i < link->
nfn; i++) {
753 link->
fn[
i].space = *
p; p++;
769 for (i = 0; i <
max; i++) {
775 s[j++] = (*p == 0xff) ?
'\0' : *p;
776 if ((*p ==
'\0') || (*p == 0xff))
781 if ((*p == 0xff) || (++p ==
q))
789 return (ns == max) ? 0 : -
EINVAL;
800 vers_1->
major = *p; p++;
801 vers_1->
minor = *p; p++;
806 vers_1->
str, vers_1->
ofs, &vers_1->
ns);
818 altstr->
str, altstr->
ofs, &altstr->
ns);
833 jedec->
id[nid].mfr = p[0];
834 jedec->
id[nid].info = p[1];
885 rmsz = (*p & 0x3c) >> 2;
891 for (i = 0; i <= rasz; i++)
892 config->
base += p[i] << (8*i);
894 for (i = 0; i < 4; i++)
895 config->
rmask[i] = 0;
896 for (i = 0; i <= rmsz; i++)
897 config->
rmask[i>>2] += p[i] << (8*(i%4));
916 for (i = 0; i < 7; i++)
925 if ((*p & 0x7f) < 100)
927 (*p & 0x7f) * scale / 100;
950 if ((scale & 3) != 3) {
958 if ((scale & 7) != 7) {
995 io->
nwin = (*p & 0x0f) + 1;
996 bsz = (*p & 0x30) >> 4;
999 lsz = (*p & 0xc0) >> 6;
1004 for (i = 0; i < io->
nwin; i++) {
1005 io->
win[
i].base = 0;
1007 for (j = 0; j < bsz; j++, p++) {
1010 io->
win[
i].base += *p << (j*8);
1012 for (j = 0; j < lsz; j++, p++) {
1015 io->
win[
i].len += *p << (j*8);
1024 int i,
j, asz, lsz, has_ha;
1030 mem->
nwin = (*p & 0x07) + 1;
1031 lsz = (*p & 0x18) >> 3;
1032 asz = (*p & 0x60) >> 5;
1033 has_ha = (*p & 0x80);
1037 for (i = 0; i < mem->
nwin; i++) {
1039 for (j = 0; j < lsz; j++, p++) {
1044 for (j = 0; j < asz; j++, p++) {
1050 for (j = 0; j < asz; j++, p++) {
1055 mem->
win[
i].len = len << 8;
1056 mem->
win[
i].card_addr = ca << 8;
1057 mem->
win[
i].host_addr = ha << 8;
1078 static int parse_cftable_entry(
tuple_t *tuple,
1085 entry->
index = *p & 0x3f;
1110 if ((features & 3) > 0) {
1111 p = parse_power(p, q, &entry->
vcc);
1116 if ((features & 3) > 1) {
1117 p = parse_power(p, q, &entry->
vpp1);
1122 if ((features & 3) > 2) {
1123 p = parse_power(p, q, &entry->
vpp2);
1130 if (features & 0x04) {
1131 p = parse_timing(p, q, &entry->
timing);
1141 if (features & 0x08) {
1142 p = parse_io(p, q, &entry->
io);
1149 if (features & 0x10) {
1150 p = parse_irq(p, q, &entry->
irq);
1156 switch (features & 0x60) {
1162 entry->
mem.
win[0].len = get_unaligned_le16(p) << 8;
1163 entry->
mem.
win[0].card_addr = 0;
1164 entry->
mem.
win[0].host_addr = 0;
1171 entry->
mem.
win[0].len = get_unaligned_le16(p) << 8;
1172 entry->
mem.
win[0].card_addr = get_unaligned_le16(p + 2) << 8;
1173 entry->
mem.
win[0].host_addr = 0;
1179 p = parse_mem(p, q, &entry->
mem);
1186 if (features & 0x80) {
1189 entry->
flags |= (*p << 8);
1213 geo->
geo[
n].buswidth = p[0];
1214 geo->
geo[
n].erase_block = 1 << (p[1]-1);
1215 geo->
geo[
n].read_block = 1 << (p[2]-1);
1216 geo->
geo[
n].write_block = 1 << (p[3]-1);
1217 geo->
geo[
n].partition = 1 << (p[4]-1);
1218 geo->
geo[
n].interleave = 1 << (p[5]-1);
1238 v2->
dindex = get_unaligned_le16(p + 2);
1259 for (i = 0; i < 30; i++) {
1297 ret = parse_device(tuple, &parse->
device);
1300 ret = parse_checksum(tuple, &parse->
checksum);
1304 ret = parse_longlink(tuple, &parse->
longlink);
1310 ret = parse_vers_1(tuple, &parse->
version_1);
1313 ret = parse_altstr(tuple, &parse->
altstr);
1317 ret = parse_jedec(tuple, &parse->
jedec);
1320 ret = parse_manfid(tuple, &parse->
manfid);
1323 ret = parse_funcid(tuple, &parse->
funcid);
1326 ret = parse_funce(tuple, &parse->
funce);
1336 ret = parse_device_geo(tuple, &parse->
device_geo);
1339 ret = parse_vers_2(tuple, &parse->
vers_2);
1342 ret = parse_org(tuple, &parse->
org);
1346 ret = parse_format(tuple, &parse->
format);
1357 pr_debug(
"parse_tuple failed %d\n", ret);
1380 unsigned int count = 0;
1397 if (tuple ==
NULL) {
1408 count = reserved = 0;
1430 if (!dev_ok && !ident_ok)
1433 for (count = 1; count <
MAX_TUPLES; count++) {
1442 if ((count == MAX_TUPLES) || (reserved > 5) ||
1443 ((!dev_ok || !ident_ok) && (count > 10)))
1450 if (!dev_ok || !ident_ok || !count) {
1465 #define to_socket(_dev) container_of(_dev, struct pcmcia_socket, dev)
1468 loff_t off,
size_t count)
1507 tempbuffer[i + 2] = tuplebuffer[i] & 0xff;
1510 if (((i + pointer) >= off) &&
1511 (i + pointer) < (off + count)) {
1512 buf[
ret] = tempbuffer[
i];
1520 if (pointer >= (off + count))
1538 char *
buf, loff_t off,
size_t count)
1540 unsigned int size = 0x200;
1546 unsigned int chains = 1;
1548 if (off + count > size)
1560 count = pccard_extract_cis(s, buf, off, count);
1569 char *buf, loff_t off,
size_t count)
1598 .read = pccard_show_cis,
1599 .write = pccard_store_cis,