ops-mace.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. * Copyright (C) 2000, 2001 Keith M Wesolowski
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/pci.h>
  10. #include <linux/types.h>
  11. #include <asm/pci.h>
  12. #include <asm/ip32/mace.h>
  13. #if 0
  14. # define DPRINTK(args...) printk(args);
  15. #else
  16. # define DPRINTK(args...)
  17. #endif
  18. /*
  19. * O2 has up to 5 PCI devices connected into the MACE bridge. The device
  20. * map looks like this:
  21. *
  22. * 0 aic7xxx 0
  23. * 1 aic7xxx 1
  24. * 2 expansion slot
  25. * 3 N/C
  26. * 4 N/C
  27. */
  28. static inline int mkaddr(struct pci_bus *bus, unsigned int devfn,
  29. unsigned int reg)
  30. {
  31. return ((bus->number & 0xff) << 16) |
  32. ((devfn & 0xff) << 8) |
  33. (reg & 0xfc);
  34. }
  35. static int
  36. mace_pci_read_config(struct pci_bus *bus, unsigned int devfn,
  37. int reg, int size, u32 *val)
  38. {
  39. u32 control = mace->pci.control;
  40. /* disable master aborts interrupts during config read */
  41. mace->pci.control = control & ~MACEPCI_CONTROL_MAR_INT;
  42. mace->pci.config_addr = mkaddr(bus, devfn, reg);
  43. switch (size) {
  44. case 1:
  45. *val = mace->pci.config_data.b[(reg & 3) ^ 3];
  46. break;
  47. case 2:
  48. *val = mace->pci.config_data.w[((reg >> 1) & 1) ^ 1];
  49. break;
  50. case 4:
  51. *val = mace->pci.config_data.l;
  52. break;
  53. }
  54. /* ack possible master abort */
  55. mace->pci.error &= ~MACEPCI_ERROR_MASTER_ABORT;
  56. mace->pci.control = control;
  57. /*
  58. * someone forgot to set the ultra bit for the onboard
  59. * scsi chips; we fake it here
  60. */
  61. if (bus->number == 0 && reg == 0x40 && size == 4 &&
  62. (devfn == (1 << 3) || devfn == (2 << 3)))
  63. *val |= 0x1000;
  64. DPRINTK("read%d: reg=%08x,val=%02x\n", size * 8, reg, *val);
  65. return PCIBIOS_SUCCESSFUL;
  66. }
  67. static int
  68. mace_pci_write_config(struct pci_bus *bus, unsigned int devfn,
  69. int reg, int size, u32 val)
  70. {
  71. mace->pci.config_addr = mkaddr(bus, devfn, reg);
  72. switch (size) {
  73. case 1:
  74. mace->pci.config_data.b[(reg & 3) ^ 3] = val;
  75. break;
  76. case 2:
  77. mace->pci.config_data.w[((reg >> 1) & 1) ^ 1] = val;
  78. break;
  79. case 4:
  80. mace->pci.config_data.l = val;
  81. break;
  82. }
  83. DPRINTK("write%d: reg=%08x,val=%02x\n", size * 8, reg, val);
  84. return PCIBIOS_SUCCESSFUL;
  85. }
  86. struct pci_ops mace_pci_ops = {
  87. .read = mace_pci_read_config,
  88. .write = mace_pci_write_config,
  89. };