access.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/pci.h>
  3. #include <linux/module.h>
  4. #include <linux/slab.h>
  5. #include <linux/ioport.h>
  6. #include <linux/wait.h>
  7. #include "pci.h"
  8. /*
  9. * This interrupt-safe spinlock protects all accesses to PCI
  10. * configuration space.
  11. */
  12. DEFINE_RAW_SPINLOCK(pci_lock);
  13. /*
  14. * Wrappers for all PCI configuration access functions. They just check
  15. * alignment, do locking and call the low-level functions pointed to
  16. * by pci_dev->ops.
  17. */
  18. #define PCI_byte_BAD 0
  19. #define PCI_word_BAD (pos & 1)
  20. #define PCI_dword_BAD (pos & 3)
  21. #ifdef CONFIG_PCI_LOCKLESS_CONFIG
  22. # define pci_lock_config(f) do { (void)(f); } while (0)
  23. # define pci_unlock_config(f) do { (void)(f); } while (0)
  24. #else
  25. # define pci_lock_config(f) raw_spin_lock_irqsave(&pci_lock, f)
  26. # define pci_unlock_config(f) raw_spin_unlock_irqrestore(&pci_lock, f)
  27. #endif
  28. #define PCI_OP_READ(size, type, len) \
  29. int noinline pci_bus_read_config_##size \
  30. (struct pci_bus *bus, unsigned int devfn, int pos, type *value) \
  31. { \
  32. unsigned long flags; \
  33. u32 data = 0; \
  34. int res; \
  35. \
  36. if (PCI_##size##_BAD) \
  37. return PCIBIOS_BAD_REGISTER_NUMBER; \
  38. \
  39. pci_lock_config(flags); \
  40. res = bus->ops->read(bus, devfn, pos, len, &data); \
  41. if (res) \
  42. PCI_SET_ERROR_RESPONSE(value); \
  43. else \
  44. *value = (type)data; \
  45. pci_unlock_config(flags); \
  46. \
  47. return res; \
  48. }
  49. #define PCI_OP_WRITE(size, type, len) \
  50. int noinline pci_bus_write_config_##size \
  51. (struct pci_bus *bus, unsigned int devfn, int pos, type value) \
  52. { \
  53. unsigned long flags; \
  54. int res; \
  55. \
  56. if (PCI_##size##_BAD) \
  57. return PCIBIOS_BAD_REGISTER_NUMBER; \
  58. \
  59. pci_lock_config(flags); \
  60. res = bus->ops->write(bus, devfn, pos, len, value); \
  61. pci_unlock_config(flags); \
  62. \
  63. return res; \
  64. }
  65. PCI_OP_READ(byte, u8, 1)
  66. PCI_OP_READ(word, u16, 2)
  67. PCI_OP_READ(dword, u32, 4)
  68. PCI_OP_WRITE(byte, u8, 1)
  69. PCI_OP_WRITE(word, u16, 2)
  70. PCI_OP_WRITE(dword, u32, 4)
  71. EXPORT_SYMBOL(pci_bus_read_config_byte);
  72. EXPORT_SYMBOL(pci_bus_read_config_word);
  73. EXPORT_SYMBOL(pci_bus_read_config_dword);
  74. EXPORT_SYMBOL(pci_bus_write_config_byte);
  75. EXPORT_SYMBOL(pci_bus_write_config_word);
  76. EXPORT_SYMBOL(pci_bus_write_config_dword);
  77. int pci_generic_config_read(struct pci_bus *bus, unsigned int devfn,
  78. int where, int size, u32 *val)
  79. {
  80. void __iomem *addr;
  81. addr = bus->ops->map_bus(bus, devfn, where);
  82. if (!addr)
  83. return PCIBIOS_DEVICE_NOT_FOUND;
  84. if (size == 1)
  85. *val = readb(addr);
  86. else if (size == 2)
  87. *val = readw(addr);
  88. else
  89. *val = readl(addr);
  90. return PCIBIOS_SUCCESSFUL;
  91. }
  92. EXPORT_SYMBOL_GPL(pci_generic_config_read);
  93. int pci_generic_config_write(struct pci_bus *bus, unsigned int devfn,
  94. int where, int size, u32 val)
  95. {
  96. void __iomem *addr;
  97. addr = bus->ops->map_bus(bus, devfn, where);
  98. if (!addr)
  99. return PCIBIOS_DEVICE_NOT_FOUND;
  100. if (size == 1)
  101. writeb(val, addr);
  102. else if (size == 2)
  103. writew(val, addr);
  104. else
  105. writel(val, addr);
  106. return PCIBIOS_SUCCESSFUL;
  107. }
  108. EXPORT_SYMBOL_GPL(pci_generic_config_write);
  109. int pci_generic_config_read32(struct pci_bus *bus, unsigned int devfn,
  110. int where, int size, u32 *val)
  111. {
  112. void __iomem *addr;
  113. addr = bus->ops->map_bus(bus, devfn, where & ~0x3);
  114. if (!addr)
  115. return PCIBIOS_DEVICE_NOT_FOUND;
  116. *val = readl(addr);
  117. if (size <= 2)
  118. *val = (*val >> (8 * (where & 3))) & ((1 << (size * 8)) - 1);
  119. return PCIBIOS_SUCCESSFUL;
  120. }
  121. EXPORT_SYMBOL_GPL(pci_generic_config_read32);
  122. int pci_generic_config_write32(struct pci_bus *bus, unsigned int devfn,
  123. int where, int size, u32 val)
  124. {
  125. void __iomem *addr;
  126. u32 mask, tmp;
  127. addr = bus->ops->map_bus(bus, devfn, where & ~0x3);
  128. if (!addr)
  129. return PCIBIOS_DEVICE_NOT_FOUND;
  130. if (size == 4) {
  131. writel(val, addr);
  132. return PCIBIOS_SUCCESSFUL;
  133. }
  134. /*
  135. * In general, hardware that supports only 32-bit writes on PCI is
  136. * not spec-compliant. For example, software may perform a 16-bit
  137. * write. If the hardware only supports 32-bit accesses, we must
  138. * do a 32-bit read, merge in the 16 bits we intend to write,
  139. * followed by a 32-bit write. If the 16 bits we *don't* intend to
  140. * write happen to have any RW1C (write-one-to-clear) bits set, we
  141. * just inadvertently cleared something we shouldn't have.
  142. */
  143. if (!bus->unsafe_warn) {
  144. dev_warn(&bus->dev, "%d-byte config write to %04x:%02x:%02x.%d offset %#x may corrupt adjacent RW1C bits\n",
  145. size, pci_domain_nr(bus), bus->number,
  146. PCI_SLOT(devfn), PCI_FUNC(devfn), where);
  147. bus->unsafe_warn = 1;
  148. }
  149. mask = ~(((1 << (size * 8)) - 1) << ((where & 0x3) * 8));
  150. tmp = readl(addr) & mask;
  151. tmp |= val << ((where & 0x3) * 8);
  152. writel(tmp, addr);
  153. return PCIBIOS_SUCCESSFUL;
  154. }
  155. EXPORT_SYMBOL_GPL(pci_generic_config_write32);
  156. /**
  157. * pci_bus_set_ops - Set raw operations of pci bus
  158. * @bus: pci bus struct
  159. * @ops: new raw operations
  160. *
  161. * Return previous raw operations
  162. */
  163. struct pci_ops *pci_bus_set_ops(struct pci_bus *bus, struct pci_ops *ops)
  164. {
  165. struct pci_ops *old_ops;
  166. unsigned long flags;
  167. raw_spin_lock_irqsave(&pci_lock, flags);
  168. old_ops = bus->ops;
  169. bus->ops = ops;
  170. raw_spin_unlock_irqrestore(&pci_lock, flags);
  171. return old_ops;
  172. }
  173. EXPORT_SYMBOL(pci_bus_set_ops);
  174. /*
  175. * The following routines are to prevent the user from accessing PCI config
  176. * space when it's unsafe to do so. Some devices require this during BIST and
  177. * we're required to prevent it during D-state transitions.
  178. *
  179. * We have a bit per device to indicate it's blocked and a global wait queue
  180. * for callers to sleep on until devices are unblocked.
  181. */
  182. static DECLARE_WAIT_QUEUE_HEAD(pci_cfg_wait);
  183. static noinline void pci_wait_cfg(struct pci_dev *dev)
  184. __must_hold(&pci_lock)
  185. {
  186. do {
  187. raw_spin_unlock_irq(&pci_lock);
  188. wait_event(pci_cfg_wait, !dev->block_cfg_access);
  189. raw_spin_lock_irq(&pci_lock);
  190. } while (dev->block_cfg_access);
  191. }
  192. /* Returns 0 on success, negative values indicate error. */
  193. #define PCI_USER_READ_CONFIG(size, type) \
  194. int pci_user_read_config_##size \
  195. (struct pci_dev *dev, int pos, type *val) \
  196. { \
  197. u32 data = -1; \
  198. int ret; \
  199. \
  200. if (PCI_##size##_BAD) \
  201. return -EINVAL; \
  202. \
  203. raw_spin_lock_irq(&pci_lock); \
  204. if (unlikely(dev->block_cfg_access)) \
  205. pci_wait_cfg(dev); \
  206. ret = dev->bus->ops->read(dev->bus, dev->devfn, \
  207. pos, sizeof(type), &data); \
  208. raw_spin_unlock_irq(&pci_lock); \
  209. if (ret) \
  210. PCI_SET_ERROR_RESPONSE(val); \
  211. else \
  212. *val = (type)data; \
  213. \
  214. return pcibios_err_to_errno(ret); \
  215. } \
  216. EXPORT_SYMBOL_GPL(pci_user_read_config_##size);
  217. /* Returns 0 on success, negative values indicate error. */
  218. #define PCI_USER_WRITE_CONFIG(size, type) \
  219. int pci_user_write_config_##size \
  220. (struct pci_dev *dev, int pos, type val) \
  221. { \
  222. int ret; \
  223. \
  224. if (PCI_##size##_BAD) \
  225. return -EINVAL; \
  226. \
  227. raw_spin_lock_irq(&pci_lock); \
  228. if (unlikely(dev->block_cfg_access)) \
  229. pci_wait_cfg(dev); \
  230. ret = dev->bus->ops->write(dev->bus, dev->devfn, \
  231. pos, sizeof(type), val); \
  232. raw_spin_unlock_irq(&pci_lock); \
  233. \
  234. return pcibios_err_to_errno(ret); \
  235. } \
  236. EXPORT_SYMBOL_GPL(pci_user_write_config_##size);
  237. PCI_USER_READ_CONFIG(byte, u8)
  238. PCI_USER_READ_CONFIG(word, u16)
  239. PCI_USER_READ_CONFIG(dword, u32)
  240. PCI_USER_WRITE_CONFIG(byte, u8)
  241. PCI_USER_WRITE_CONFIG(word, u16)
  242. PCI_USER_WRITE_CONFIG(dword, u32)
  243. /**
  244. * pci_cfg_access_lock - Lock PCI config reads/writes
  245. * @dev: pci device struct
  246. *
  247. * When access is locked, any userspace reads or writes to config
  248. * space and concurrent lock requests will sleep until access is
  249. * allowed via pci_cfg_access_unlock() again.
  250. */
  251. void pci_cfg_access_lock(struct pci_dev *dev)
  252. {
  253. might_sleep();
  254. raw_spin_lock_irq(&pci_lock);
  255. if (dev->block_cfg_access)
  256. pci_wait_cfg(dev);
  257. dev->block_cfg_access = 1;
  258. raw_spin_unlock_irq(&pci_lock);
  259. }
  260. EXPORT_SYMBOL_GPL(pci_cfg_access_lock);
  261. /**
  262. * pci_cfg_access_trylock - try to lock PCI config reads/writes
  263. * @dev: pci device struct
  264. *
  265. * Same as pci_cfg_access_lock, but will return 0 if access is
  266. * already locked, 1 otherwise. This function can be used from
  267. * atomic contexts.
  268. */
  269. bool pci_cfg_access_trylock(struct pci_dev *dev)
  270. {
  271. unsigned long flags;
  272. bool locked = true;
  273. raw_spin_lock_irqsave(&pci_lock, flags);
  274. if (dev->block_cfg_access)
  275. locked = false;
  276. else
  277. dev->block_cfg_access = 1;
  278. raw_spin_unlock_irqrestore(&pci_lock, flags);
  279. return locked;
  280. }
  281. EXPORT_SYMBOL_GPL(pci_cfg_access_trylock);
  282. /**
  283. * pci_cfg_access_unlock - Unlock PCI config reads/writes
  284. * @dev: pci device struct
  285. *
  286. * This function allows PCI config accesses to resume.
  287. */
  288. void pci_cfg_access_unlock(struct pci_dev *dev)
  289. {
  290. unsigned long flags;
  291. raw_spin_lock_irqsave(&pci_lock, flags);
  292. /*
  293. * This indicates a problem in the caller, but we don't need
  294. * to kill them, unlike a double-block above.
  295. */
  296. WARN_ON(!dev->block_cfg_access);
  297. dev->block_cfg_access = 0;
  298. raw_spin_unlock_irqrestore(&pci_lock, flags);
  299. wake_up_all(&pci_cfg_wait);
  300. }
  301. EXPORT_SYMBOL_GPL(pci_cfg_access_unlock);
  302. static inline int pcie_cap_version(const struct pci_dev *dev)
  303. {
  304. return pcie_caps_reg(dev) & PCI_EXP_FLAGS_VERS;
  305. }
  306. bool pcie_cap_has_lnkctl(const struct pci_dev *dev)
  307. {
  308. int type = pci_pcie_type(dev);
  309. return type == PCI_EXP_TYPE_ENDPOINT ||
  310. type == PCI_EXP_TYPE_LEG_END ||
  311. type == PCI_EXP_TYPE_ROOT_PORT ||
  312. type == PCI_EXP_TYPE_UPSTREAM ||
  313. type == PCI_EXP_TYPE_DOWNSTREAM ||
  314. type == PCI_EXP_TYPE_PCI_BRIDGE ||
  315. type == PCI_EXP_TYPE_PCIE_BRIDGE;
  316. }
  317. bool pcie_cap_has_lnkctl2(const struct pci_dev *dev)
  318. {
  319. return pcie_cap_has_lnkctl(dev) && pcie_cap_version(dev) > 1;
  320. }
  321. static inline bool pcie_cap_has_sltctl(const struct pci_dev *dev)
  322. {
  323. return pcie_downstream_port(dev) &&
  324. pcie_caps_reg(dev) & PCI_EXP_FLAGS_SLOT;
  325. }
  326. bool pcie_cap_has_rtctl(const struct pci_dev *dev)
  327. {
  328. int type = pci_pcie_type(dev);
  329. return type == PCI_EXP_TYPE_ROOT_PORT ||
  330. type == PCI_EXP_TYPE_RC_EC;
  331. }
  332. static bool pcie_capability_reg_implemented(struct pci_dev *dev, int pos)
  333. {
  334. if (!pci_is_pcie(dev))
  335. return false;
  336. switch (pos) {
  337. case PCI_EXP_FLAGS:
  338. return true;
  339. case PCI_EXP_DEVCAP:
  340. case PCI_EXP_DEVCTL:
  341. case PCI_EXP_DEVSTA:
  342. return true;
  343. case PCI_EXP_LNKCAP:
  344. case PCI_EXP_LNKCTL:
  345. case PCI_EXP_LNKSTA:
  346. return pcie_cap_has_lnkctl(dev);
  347. case PCI_EXP_SLTCAP:
  348. case PCI_EXP_SLTCTL:
  349. case PCI_EXP_SLTSTA:
  350. return pcie_cap_has_sltctl(dev);
  351. case PCI_EXP_RTCTL:
  352. case PCI_EXP_RTCAP:
  353. case PCI_EXP_RTSTA:
  354. return pcie_cap_has_rtctl(dev);
  355. case PCI_EXP_DEVCAP2:
  356. case PCI_EXP_DEVCTL2:
  357. return pcie_cap_version(dev) > 1;
  358. case PCI_EXP_LNKCAP2:
  359. case PCI_EXP_LNKCTL2:
  360. case PCI_EXP_LNKSTA2:
  361. return pcie_cap_has_lnkctl2(dev);
  362. default:
  363. return false;
  364. }
  365. }
  366. /*
  367. * Note that these accessor functions are only for the "PCI Express
  368. * Capability" (see PCIe spec r3.0, sec 7.8). They do not apply to the
  369. * other "PCI Express Extended Capabilities" (AER, VC, ACS, MFVC, etc.)
  370. */
  371. int pcie_capability_read_word(struct pci_dev *dev, int pos, u16 *val)
  372. {
  373. int ret;
  374. *val = 0;
  375. if (pos & 1)
  376. return PCIBIOS_BAD_REGISTER_NUMBER;
  377. if (pcie_capability_reg_implemented(dev, pos)) {
  378. ret = pci_read_config_word(dev, pci_pcie_cap(dev) + pos, val);
  379. /*
  380. * Reset *val to 0 if pci_read_config_word() fails; it may
  381. * have been written as 0xFFFF (PCI_ERROR_RESPONSE) if the
  382. * config read failed on PCI.
  383. */
  384. if (ret)
  385. *val = 0;
  386. return ret;
  387. }
  388. /*
  389. * For Functions that do not implement the Slot Capabilities,
  390. * Slot Status, and Slot Control registers, these spaces must
  391. * be hardwired to 0b, with the exception of the Presence Detect
  392. * State bit in the Slot Status register of Downstream Ports,
  393. * which must be hardwired to 1b. (PCIe Base Spec 3.0, sec 7.8)
  394. */
  395. if (pci_is_pcie(dev) && pcie_downstream_port(dev) &&
  396. pos == PCI_EXP_SLTSTA)
  397. *val = PCI_EXP_SLTSTA_PDS;
  398. return 0;
  399. }
  400. EXPORT_SYMBOL(pcie_capability_read_word);
  401. int pcie_capability_read_dword(struct pci_dev *dev, int pos, u32 *val)
  402. {
  403. int ret;
  404. *val = 0;
  405. if (pos & 3)
  406. return PCIBIOS_BAD_REGISTER_NUMBER;
  407. if (pcie_capability_reg_implemented(dev, pos)) {
  408. ret = pci_read_config_dword(dev, pci_pcie_cap(dev) + pos, val);
  409. /*
  410. * Reset *val to 0 if pci_read_config_dword() fails; it may
  411. * have been written as 0xFFFFFFFF (PCI_ERROR_RESPONSE) if
  412. * the config read failed on PCI.
  413. */
  414. if (ret)
  415. *val = 0;
  416. return ret;
  417. }
  418. if (pci_is_pcie(dev) && pcie_downstream_port(dev) &&
  419. pos == PCI_EXP_SLTSTA)
  420. *val = PCI_EXP_SLTSTA_PDS;
  421. return 0;
  422. }
  423. EXPORT_SYMBOL(pcie_capability_read_dword);
  424. int pcie_capability_write_word(struct pci_dev *dev, int pos, u16 val)
  425. {
  426. if (pos & 1)
  427. return PCIBIOS_BAD_REGISTER_NUMBER;
  428. if (!pcie_capability_reg_implemented(dev, pos))
  429. return 0;
  430. return pci_write_config_word(dev, pci_pcie_cap(dev) + pos, val);
  431. }
  432. EXPORT_SYMBOL(pcie_capability_write_word);
  433. int pcie_capability_write_dword(struct pci_dev *dev, int pos, u32 val)
  434. {
  435. if (pos & 3)
  436. return PCIBIOS_BAD_REGISTER_NUMBER;
  437. if (!pcie_capability_reg_implemented(dev, pos))
  438. return 0;
  439. return pci_write_config_dword(dev, pci_pcie_cap(dev) + pos, val);
  440. }
  441. EXPORT_SYMBOL(pcie_capability_write_dword);
  442. int pcie_capability_clear_and_set_word_unlocked(struct pci_dev *dev, int pos,
  443. u16 clear, u16 set)
  444. {
  445. int ret;
  446. u16 val;
  447. ret = pcie_capability_read_word(dev, pos, &val);
  448. if (ret)
  449. return ret;
  450. val &= ~clear;
  451. val |= set;
  452. return pcie_capability_write_word(dev, pos, val);
  453. }
  454. EXPORT_SYMBOL(pcie_capability_clear_and_set_word_unlocked);
  455. int pcie_capability_clear_and_set_word_locked(struct pci_dev *dev, int pos,
  456. u16 clear, u16 set)
  457. {
  458. unsigned long flags;
  459. int ret;
  460. spin_lock_irqsave(&dev->pcie_cap_lock, flags);
  461. ret = pcie_capability_clear_and_set_word_unlocked(dev, pos, clear, set);
  462. spin_unlock_irqrestore(&dev->pcie_cap_lock, flags);
  463. return ret;
  464. }
  465. EXPORT_SYMBOL(pcie_capability_clear_and_set_word_locked);
  466. int pcie_capability_clear_and_set_dword(struct pci_dev *dev, int pos,
  467. u32 clear, u32 set)
  468. {
  469. int ret;
  470. u32 val;
  471. ret = pcie_capability_read_dword(dev, pos, &val);
  472. if (ret)
  473. return ret;
  474. val &= ~clear;
  475. val |= set;
  476. return pcie_capability_write_dword(dev, pos, val);
  477. }
  478. EXPORT_SYMBOL(pcie_capability_clear_and_set_dword);
  479. int pci_read_config_byte(const struct pci_dev *dev, int where, u8 *val)
  480. {
  481. if (pci_dev_is_disconnected(dev)) {
  482. PCI_SET_ERROR_RESPONSE(val);
  483. return PCIBIOS_DEVICE_NOT_FOUND;
  484. }
  485. return pci_bus_read_config_byte(dev->bus, dev->devfn, where, val);
  486. }
  487. EXPORT_SYMBOL(pci_read_config_byte);
  488. int pci_read_config_word(const struct pci_dev *dev, int where, u16 *val)
  489. {
  490. if (pci_dev_is_disconnected(dev)) {
  491. PCI_SET_ERROR_RESPONSE(val);
  492. return PCIBIOS_DEVICE_NOT_FOUND;
  493. }
  494. return pci_bus_read_config_word(dev->bus, dev->devfn, where, val);
  495. }
  496. EXPORT_SYMBOL(pci_read_config_word);
  497. int pci_read_config_dword(const struct pci_dev *dev, int where,
  498. u32 *val)
  499. {
  500. if (pci_dev_is_disconnected(dev)) {
  501. PCI_SET_ERROR_RESPONSE(val);
  502. return PCIBIOS_DEVICE_NOT_FOUND;
  503. }
  504. return pci_bus_read_config_dword(dev->bus, dev->devfn, where, val);
  505. }
  506. EXPORT_SYMBOL(pci_read_config_dword);
  507. int pci_write_config_byte(const struct pci_dev *dev, int where, u8 val)
  508. {
  509. if (pci_dev_is_disconnected(dev))
  510. return PCIBIOS_DEVICE_NOT_FOUND;
  511. return pci_bus_write_config_byte(dev->bus, dev->devfn, where, val);
  512. }
  513. EXPORT_SYMBOL(pci_write_config_byte);
  514. int pci_write_config_word(const struct pci_dev *dev, int where, u16 val)
  515. {
  516. if (pci_dev_is_disconnected(dev))
  517. return PCIBIOS_DEVICE_NOT_FOUND;
  518. return pci_bus_write_config_word(dev->bus, dev->devfn, where, val);
  519. }
  520. EXPORT_SYMBOL(pci_write_config_word);
  521. int pci_write_config_dword(const struct pci_dev *dev, int where,
  522. u32 val)
  523. {
  524. if (pci_dev_is_disconnected(dev))
  525. return PCIBIOS_DEVICE_NOT_FOUND;
  526. return pci_bus_write_config_dword(dev->bus, dev->devfn, where, val);
  527. }
  528. EXPORT_SYMBOL(pci_write_config_dword);
  529. void pci_clear_and_set_config_dword(const struct pci_dev *dev, int pos,
  530. u32 clear, u32 set)
  531. {
  532. u32 val;
  533. pci_read_config_dword(dev, pos, &val);
  534. val &= ~clear;
  535. val |= set;
  536. pci_write_config_dword(dev, pos, val);
  537. }
  538. EXPORT_SYMBOL(pci_clear_and_set_config_dword);