2 * The PCI Library -- User Access
4 * Copyright (c) 1997--2008 Martin Mares <mj@ucw.cz>
6 * Can be freely distributed and used under the terms of the GNU GPL.
17 pci_scan_bus(struct pci_access *a)
23 pci_alloc_dev(struct pci_access *a)
25 struct pci_dev *d = pci_malloc(a, sizeof(struct pci_dev));
27 memset(d, 0, sizeof(*d));
29 d->methods = a->methods;
31 if (d->methods->init_dev)
32 d->methods->init_dev(d);
37 pci_link_dev(struct pci_access *a, struct pci_dev *d)
46 pci_get_dev(struct pci_access *a, int domain, int bus, int dev, int func)
48 struct pci_dev *d = pci_alloc_dev(a);
57 void pci_free_dev(struct pci_dev *d)
59 if (d->methods->cleanup_dev)
60 d->methods->cleanup_dev(d);
62 pci_mfree(d->phy_slot);
67 pci_read_data(struct pci_dev *d, void *buf, int pos, int len)
70 d->access->error("Unaligned read: pos=%02x, len=%d", pos, len);
71 if (pos + len <= d->cache_len)
72 memcpy(buf, d->cache + pos, len);
73 else if (!d->methods->read(d, pos, buf, len))
74 memset(buf, 0xff, len);
78 pci_read_byte(struct pci_dev *d, int pos)
81 pci_read_data(d, &buf, pos, 1);
86 pci_read_word(struct pci_dev *d, int pos)
89 pci_read_data(d, &buf, pos, 2);
90 return le16_to_cpu(buf);
94 pci_read_long(struct pci_dev *d, int pos)
97 pci_read_data(d, &buf, pos, 4);
98 return le32_to_cpu(buf);
102 pci_read_block(struct pci_dev *d, int pos, byte *buf, int len)
104 return d->methods->read(d, pos, buf, len);
108 pci_read_vpd(struct pci_dev *d, int pos, byte *buf, int len)
110 return d->methods->read_vpd ? d->methods->read_vpd(d, pos, buf, len) : 0;
114 pci_write_data(struct pci_dev *d, void *buf, int pos, int len)
117 d->access->error("Unaligned write: pos=%02x,len=%d", pos, len);
118 if (pos + len <= d->cache_len)
119 memcpy(d->cache + pos, buf, len);
120 return d->methods->write(d, pos, buf, len);
124 pci_write_byte(struct pci_dev *d, int pos, byte data)
126 return pci_write_data(d, &data, pos, 1);
130 pci_write_word(struct pci_dev *d, int pos, word data)
132 word buf = cpu_to_le16(data);
133 return pci_write_data(d, &buf, pos, 2);
137 pci_write_long(struct pci_dev *d, int pos, u32 data)
139 u32 buf = cpu_to_le32(data);
140 return pci_write_data(d, &buf, pos, 4);
144 pci_write_block(struct pci_dev *d, int pos, byte *buf, int len)
146 if (pos < d->cache_len)
148 int l = (pos + len >= d->cache_len) ? (d->cache_len - pos) : len;
149 memcpy(d->cache + pos, buf, l);
151 return d->methods->write(d, pos, buf, len);
155 pci_fill_info_v31(struct pci_dev *d, int flags)
157 if (flags & PCI_FILL_RESCAN)
159 flags &= ~PCI_FILL_RESCAN;
163 if (flags & ~d->known_fields)
164 d->known_fields |= d->methods->fill_info(d, flags & ~d->known_fields);
165 return d->known_fields;
168 /* In version 3.1, pci_fill_info got new flags => versioned alias */
169 STATIC_ALIAS(int pci_fill_info(struct pci_dev *d, int flags), pci_fill_info_v31(d,flags));
170 DEFINE_ALIAS(int pci_fill_info_v30(struct pci_dev *d, int flags), pci_fill_info_v31);
171 SYMBOL_VERSION(pci_fill_info_v30, pci_fill_info@LIBPCI_3.0);
172 SYMBOL_VERSION(pci_fill_info_v31, pci_fill_info@@LIBPCI_3.1);
175 pci_setup_cache(struct pci_dev *d, byte *cache, int len)