ops-mace.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. DPRINTK("read%d: reg=%08x,val=%02x\n", size * 8, reg, *val);
  59. return PCIBIOS_SUCCESSFUL;
  60. }
  61. static int
  62. mace_pci_write_config(struct pci_bus *bus, unsigned int devfn,
  63. int reg, int size, u32 val)
  64. {
  65. mace->pci.config_addr = mkaddr(bus, devfn, reg);
  66. switch (size) {
  67. case 1:
  68. mace->pci.config_data.b[(reg & 3) ^ 3] = val;
  69. break;
  70. case 2:
  71. mace->pci.config_data.w[((reg >> 1) & 1) ^ 1] = val;
  72. break;
  73. case 4:
  74. mace->pci.config_data.l = val;
  75. break;
  76. }
  77. DPRINTK("write%d: reg=%08x,val=%02x\n", size * 8, reg, val);
  78. return PCIBIOS_SUCCESSFUL;
  79. }
  80. struct pci_ops mace_pci_ops = {
  81. .read = mace_pci_read_config,
  82. .write = mace_pci_write_config,
  83. };