ops-mace.c 2.3 KB

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