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