pci_indirect.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #ifndef __I386__
  14. #include <asm/processor.h>
  15. #include <asm/io.h>
  16. #include <pci.h>
  17. #define cfg_read(val, addr, type, op) *val = op((type)(addr))
  18. #define cfg_write(val, addr, type, op) op((type *)(addr), (val))
  19. #if defined(CONFIG_MPC8260)
  20. #define INDIRECT_PCI_OP(rw, size, type, op, mask) \
  21. static int \
  22. indirect_##rw##_config_##size(struct pci_controller *hose, \
  23. pci_dev_t dev, int offset, type val) \
  24. { \
  25. out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000000); \
  26. sync(); \
  27. cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
  28. return 0; \
  29. }
  30. #else
  31. #define INDIRECT_PCI_OP(rw, size, type, op, mask) \
  32. static int \
  33. indirect_##rw##_config_##size(struct pci_controller *hose, \
  34. pci_dev_t dev, int offset, type val) \
  35. { \
  36. out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000000); \
  37. cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
  38. return 0; \
  39. }
  40. #endif
  41. #define INDIRECT_PCI_OP_ERRATA6(rw, size, type, op, mask) \
  42. static int \
  43. indirect_##rw##_config_##size(struct pci_controller *hose, \
  44. pci_dev_t dev, int offset, type val) \
  45. { \
  46. unsigned int msr = mfmsr(); \
  47. mtmsr(msr & ~(MSR_EE | MSR_CE)); \
  48. out_le32(hose->cfg_addr, dev | (offset & 0xfc) | 0x80000000); \
  49. cfg_##rw(val, hose->cfg_data + (offset & mask), type, op); \
  50. out_le32(hose->cfg_addr, 0x00000000); \
  51. mtmsr(msr); \
  52. return 0; \
  53. }
  54. INDIRECT_PCI_OP(read, byte, u8 *, in_8, 3)
  55. INDIRECT_PCI_OP(read, word, u16 *, in_le16, 2)
  56. INDIRECT_PCI_OP(read, dword, u32 *, in_le32, 0)
  57. #ifdef CONFIG_405GP
  58. INDIRECT_PCI_OP_ERRATA6(write, byte, u8, out_8, 3)
  59. INDIRECT_PCI_OP_ERRATA6(write, word, u16, out_le16, 2)
  60. INDIRECT_PCI_OP_ERRATA6(write, dword, u32, out_le32, 0)
  61. #else
  62. INDIRECT_PCI_OP(write, byte, u8, out_8, 3)
  63. INDIRECT_PCI_OP(write, word, u16, out_le16, 2)
  64. INDIRECT_PCI_OP(write, dword, u32, out_le32, 0)
  65. #endif
  66. void pci_setup_indirect(struct pci_controller* hose, u32 cfg_addr, u32 cfg_data)
  67. {
  68. pci_set_ops(hose,
  69. indirect_read_config_byte,
  70. indirect_read_config_word,
  71. indirect_read_config_dword,
  72. indirect_write_config_byte,
  73. indirect_write_config_word,
  74. indirect_write_config_dword);
  75. hose->cfg_addr = (unsigned int *) cfg_addr;
  76. hose->cfg_data = (unsigned char *) cfg_data;
  77. }
  78. #endif
  79. #endif