pci_indirect.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Support for indirect PCI bridges.
  3. *
  4. * Copyright (C) 1998 Gabriel Paubert.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <common.h>
  12. #ifdef CONFIG_PCI
  13. #include <asm/processor.h>
  14. #include <asm/io.h>
  15. #include <pci.h>
  16. #define cfg_read(val, addr, type, op) *val = op((type)(addr))
  17. #define cfg_write(val, addr, type, op) op((type *)(addr), (val))
  18. #define INDIRECT_PCI_OP(rw, size, type, op, mask) \
  19. static int \
  20. indirect_##rw##_config_##size(struct pci_controller *hose, \
  21. pci_dev_t dev, int offset, type val) \
  22. { \
  23. out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000000); \
  24. cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
  25. return 0; \
  26. }
  27. #define INDIRECT_PCI_OP_ERRATA6(rw, size, type, op, mask) \
  28. static int \
  29. indirect_##rw##_config_##size(struct pci_controller *hose, \
  30. pci_dev_t dev, int offset, type val) \
  31. { \
  32. unsigned int msr = mfmsr(); \
  33. mtmsr(msr & ~(MSR_EE | MSR_CE)); \
  34. out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000000); \
  35. cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
  36. out_le32(hose->cfg_addr, 0x00000000); \
  37. mtmsr(msr); \
  38. return 0; \
  39. }
  40. INDIRECT_PCI_OP(read, byte, u8 *, in_8, 3)
  41. INDIRECT_PCI_OP(read, word, u16 *, in_le16, 2)
  42. INDIRECT_PCI_OP(read, dword, u32 *, in_le32, 0)
  43. #ifdef CONFIG_405GP
  44. INDIRECT_PCI_OP_ERRATA6(write, byte, u8, out_8, 3)
  45. INDIRECT_PCI_OP_ERRATA6(write, word, u16, out_le16, 2)
  46. INDIRECT_PCI_OP_ERRATA6(write, dword, u32, out_le32, 0)
  47. #else
  48. INDIRECT_PCI_OP(write, byte, u8, out_8, 3)
  49. INDIRECT_PCI_OP(write, word, u16, out_le16, 2)
  50. INDIRECT_PCI_OP(write, dword, u32, out_le32, 0)
  51. #endif
  52. void pci_setup_indirect(struct pci_controller* hose, u32 cfg_addr, u32 cfg_data)
  53. {
  54. pci_set_ops(hose,
  55. indirect_read_config_byte,
  56. indirect_read_config_word,
  57. indirect_read_config_dword,
  58. indirect_write_config_byte,
  59. indirect_write_config_word,
  60. indirect_write_config_dword);
  61. hose->cfg_addr = (unsigned int *) cfg_addr;
  62. hose->cfg_data = (unsigned char *) cfg_data;
  63. }
  64. #endif