ops-titan-ht.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright 2003 PMC-Sierra
  3. * Author: Manish Lachwani (lachwani@pmc-sierra.com)
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. *
  10. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  11. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  12. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  13. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  14. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  15. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  16. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  17. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  18. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  19. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20. *
  21. * You should have received a copy of the GNU General Public License along
  22. * with this program; if not, write to the Free Software Foundation, Inc.,
  23. * 675 Mass Ave, Cambridge, MA 02139, USA.
  24. */
  25. #include <linux/types.h>
  26. #include <linux/pci.h>
  27. #include <linux/kernel.h>
  28. #include <linux/slab.h>
  29. #include <linux/delay.h>
  30. #include <asm/io.h>
  31. #include <asm/titan_dep.h>
  32. static int titan_ht_config_read_dword(struct pci_bus *bus, unsigned int devfn,
  33. int offset, u32 * val)
  34. {
  35. volatile uint32_t address;
  36. int busno;
  37. busno = bus->number;
  38. address = (busno << 16) | (devfn << 8) | (offset & 0xfc) | 0x80000000;
  39. if (busno != 0)
  40. address |= 1;
  41. /*
  42. * RM9000 HT Errata: Issue back to back HT config
  43. * transcations. Issue a BIU sync before and
  44. * after the HT cycle
  45. */
  46. *(volatile int32_t *) 0xfb0000f0 |= 0x2;
  47. udelay(30);
  48. *(volatile int32_t *) 0xfb0006f8 = address;
  49. *(val) = *(volatile int32_t *) 0xfb0006fc;
  50. udelay(30);
  51. * (volatile int32_t *) 0xfb0000f0 |= 0x2;
  52. return PCIBIOS_SUCCESSFUL;
  53. }
  54. static int titan_ht_config_read(struct pci_bus *bus, unsigned int devfn,
  55. int offset, int size, u32 * val)
  56. {
  57. uint32_t dword;
  58. titan_ht_config_read_dword(bus, devfn, offset, &dword);
  59. dword >>= ((offset & 3) << 3);
  60. dword &= (0xffffffffU >> ((4 - size) << 8));
  61. return PCIBIOS_SUCCESSFUL;
  62. }
  63. static inline int titan_ht_config_write_dword(struct pci_bus *bus,
  64. unsigned int devfn, int offset, u32 val)
  65. {
  66. volatile uint32_t address;
  67. int busno;
  68. busno = bus->number;
  69. address = (busno << 16) | (devfn << 8) | (offset & 0xfc) | 0x80000000;
  70. if (busno != 0)
  71. address |= 1;
  72. *(volatile int32_t *) 0xfb0000f0 |= 0x2;
  73. udelay(30);
  74. *(volatile int32_t *) 0xfb0006f8 = address;
  75. *(volatile int32_t *) 0xfb0006fc = val;
  76. udelay(30);
  77. *(volatile int32_t *) 0xfb0000f0 |= 0x2;
  78. return PCIBIOS_SUCCESSFUL;
  79. }
  80. static int titan_ht_config_write(struct pci_bus *bus, unsigned int devfn,
  81. int offset, int size, u32 val)
  82. {
  83. uint32_t val1, val2, mask;
  84. titan_ht_config_read_dword(bus, devfn, offset, &val2);
  85. val1 = val << ((offset & 3) << 3);
  86. mask = ~(0xffffffffU >> ((4 - size) << 8));
  87. val2 &= ~(mask << ((offset & 3) << 8));
  88. titan_ht_config_write_dword(bus, devfn, offset, val1 | val2);
  89. return PCIBIOS_SUCCESSFUL;
  90. }
  91. struct pci_ops titan_ht_pci_ops = {
  92. .read = titan_ht_config_read,
  93. .write = titan_ht_config_write,
  94. };