ops-sni.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * SNI specific PCI support for RM200/RM300.
  7. *
  8. * Copyright (C) 1997 - 2000, 2003 Ralf Baechle <ralf@linux-mips.org>
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/pci.h>
  12. #include <linux/types.h>
  13. #include <asm/sni.h>
  14. /*
  15. * It seems that on the RM200 only lower 3 bits of the 5 bit PCI device
  16. * address are decoded. We therefore manually have to reject attempts at
  17. * reading outside this range. Being on the paranoid side we only do this
  18. * test for bus 0 and hope forwarding and decoding work properly for any
  19. * subordinated busses.
  20. *
  21. * ASIC PCI only supports type 1 config cycles.
  22. */
  23. static int set_config_address(unsigned int busno, unsigned int devfn, int reg)
  24. {
  25. if ((devfn > 255) || (reg > 255))
  26. return PCIBIOS_BAD_REGISTER_NUMBER;
  27. if (busno == 0 && devfn >= PCI_DEVFN(8, 0))
  28. return PCIBIOS_DEVICE_NOT_FOUND;
  29. *(volatile u32 *)PCIMT_CONFIG_ADDRESS =
  30. ((busno & 0xff) << 16) |
  31. ((devfn & 0xff) << 8) |
  32. (reg & 0xfc);
  33. return PCIBIOS_SUCCESSFUL;
  34. }
  35. static int pcimt_read(struct pci_bus *bus, unsigned int devfn, int reg,
  36. int size, u32 * val)
  37. {
  38. int res;
  39. if ((res = set_config_address(bus->number, devfn, reg)))
  40. return res;
  41. switch (size) {
  42. case 1:
  43. *val = *(volatile u8 *) (PCIMT_CONFIG_DATA + (reg & 3));
  44. break;
  45. case 2:
  46. *val = *(volatile u16 *) (PCIMT_CONFIG_DATA + (reg & 2));
  47. break;
  48. case 4:
  49. *val = *(volatile u32 *) PCIMT_CONFIG_DATA;
  50. break;
  51. }
  52. return 0;
  53. }
  54. static int pcimt_write(struct pci_bus *bus, unsigned int devfn, int reg,
  55. int size, u32 val)
  56. {
  57. int res;
  58. if ((res = set_config_address(bus->number, devfn, reg)))
  59. return res;
  60. switch (size) {
  61. case 1:
  62. *(volatile u8 *) (PCIMT_CONFIG_DATA + (reg & 3)) = val;
  63. break;
  64. case 2:
  65. *(volatile u16 *) (PCIMT_CONFIG_DATA + (reg & 2)) = val;
  66. break;
  67. case 4:
  68. *(volatile u32 *) PCIMT_CONFIG_DATA = val;
  69. break;
  70. }
  71. return 0;
  72. }
  73. struct pci_ops sni_pci_ops = {
  74. .read = pcimt_read,
  75. .write = pcimt_write,
  76. };