pci_indirect.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Support for indirect PCI bridges.
  4. *
  5. * Copyright (C) 1998 Gabriel Paubert.
  6. */
  7. #include <common.h>
  8. #if !defined(__I386__) && !defined(CONFIG_DM_PCI)
  9. #include <asm/processor.h>
  10. #include <asm/io.h>
  11. #include <pci.h>
  12. #define cfg_read(val, addr, type, op) *val = op((type)(addr))
  13. #define cfg_write(val, addr, type, op) op((type *)(addr), (val))
  14. #if defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
  15. #define INDIRECT_PCI_OP(rw, size, type, op, mask) \
  16. static int \
  17. indirect_##rw##_config_##size(struct pci_controller *hose, \
  18. pci_dev_t dev, int offset, type val) \
  19. { \
  20. u32 b, d,f; \
  21. b = PCI_BUS(dev); d = PCI_DEV(dev); f = PCI_FUNC(dev); \
  22. b = b - hose->first_busno; \
  23. dev = PCI_BDF(b, d, f); \
  24. *(hose->cfg_addr) = dev | (offset & 0xfc) | ((offset & 0xf00) << 16) | 0x80000000; \
  25. sync(); \
  26. cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
  27. return 0; \
  28. }
  29. #else
  30. #define INDIRECT_PCI_OP(rw, size, type, op, mask) \
  31. static int \
  32. indirect_##rw##_config_##size(struct pci_controller *hose, \
  33. pci_dev_t dev, int offset, type val) \
  34. { \
  35. u32 b, d,f; \
  36. b = PCI_BUS(dev); d = PCI_DEV(dev); f = PCI_FUNC(dev); \
  37. b = b - hose->first_busno; \
  38. dev = PCI_BDF(b, d, f); \
  39. out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000000); \
  40. cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
  41. return 0; \
  42. }
  43. #endif
  44. INDIRECT_PCI_OP(read, byte, u8 *, in_8, 3)
  45. INDIRECT_PCI_OP(read, word, u16 *, in_le16, 2)
  46. INDIRECT_PCI_OP(read, dword, u32 *, in_le32, 0)
  47. INDIRECT_PCI_OP(write, byte, u8, out_8, 3)
  48. INDIRECT_PCI_OP(write, word, u16, out_le16, 2)
  49. INDIRECT_PCI_OP(write, dword, u32, out_le32, 0)
  50. void pci_setup_indirect(struct pci_controller* hose, u32 cfg_addr, u32 cfg_data)
  51. {
  52. pci_set_ops(hose,
  53. indirect_read_config_byte,
  54. indirect_read_config_word,
  55. indirect_read_config_dword,
  56. indirect_write_config_byte,
  57. indirect_write_config_word,
  58. indirect_write_config_dword);
  59. hose->cfg_addr = (unsigned int *) cfg_addr;
  60. hose->cfg_data = (unsigned char *) cfg_data;
  61. }
  62. #endif /* !__I386__ */