dataSynchronizationMemory.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * linux/arch/alpha/kernel/core_tsunami.c
  3. *
  4. * Based on code written by David A. Rusling (david.rusling@reo.mts.dec.com).
  5. *
  6. * Code common to all TSUNAMI core logic chips.
  7. */
  8. #define __EXTERN_INLINE inline
  9. #include <asm/io.h>
  10. #include <asm/core_tsunami.h>
  11. #undef __EXTERN_INLINE
  12. #include <linux/module.h>
  13. #include <linux/types.h>
  14. #include <linux/pci.h>
  15. #include <linux/sched.h>
  16. #include <linux/init.h>
  17. #include <linux/bootmem.h>
  18. #include <asm/ptrace.h>
  19. #include <asm/smp.h>
  20. #include <asm/vga.h>
  21. #include "proto.h"
  22. #include "pci_impl.h"
  23. /* Save Tsunami configuration data as the console had it set up. */
  24. struct
  25. {
  26. unsigned long wsba[4];
  27. unsigned long wsm[4];
  28. unsigned long tba[4];
  29. } saved_config[2] __attribute__((common));
  30. /*
  31. * NOTE: Herein lie back-to-back mb instructions. They are magic.
  32. * One plausible explanation is that the I/O controller does not properly
  33. * handle the system transaction. Another involves timing. Ho hum.
  34. */
  35. /*
  36. * BIOS32-style PCI interface:
  37. */
  38. #define DEBUG_CONFIG 0
  39. #if DEBUG_CONFIG
  40. # define DBG_CFG(args) printk args
  41. #else
  42. # define DBG_CFG(args)
  43. #endif
  44. /*
  45. * Given a bus, device, and function number, compute resulting
  46. * configuration space address
  47. * accordingly. It is therefore not safe to have concurrent
  48. * invocations to configuration space access routines, but there
  49. * really shouldn't be any need for this.
  50. *
  51. * Note that all config space accesses use Type 1 address format.
  52. *
  53. * Note also that type 1 is determined by non-zero bus number.
  54. *
  55. * Type 1:
  56. *
  57. * 3 3|3 3 2 2|2 2 2 2|2 2 2 2|1 1 1 1|1 1 1 1|1 1
  58. * 3 2|1 0 9 8|7 6 5 4|3 2 1 0|9 8 7 6|5 4 3 2|1 0 9 8|7 6 5 4|3 2 1 0
  59. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  60. * | | | | | | | | | | |B|B|B|B|B|B|B|B|D|D|D|D|D|F|F|F|R|R|R|R|R|R|0|1|
  61. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  62. *
  63. * 31:24 reserved
  64. * 23:16 bus number (8 bits = 128 possible buses)
  65. * 15:11 Device number (5 bits)
  66. * 10:8 function number
  67. * 7:2 register number
  68. *
  69. * Notes:
  70. * The function number selects which function of a multi-function device
  71. * (e.g., SCSI and Ethernet).
  72. *
  73. * The register selects a DWORD (32 bit) register offset. Hence it
  74. * doesn't get shifted by 2 bits as we want to "drop" the bottom two
  75. * bits.
  76. */
  77. static int
  78. mk_conf_addr(struct pci_bus *pbus, unsigned int device_fn, int where,
  79. unsigned long *pci_addr, unsigned char *type1)
  80. {
  81. struct pci_controller *hose = pbus->sysdata;
  82. unsigned long addr;
  83. u8 bus = pbus->number;
  84. DBG_CFG(("mk_conf_addr(bus=%d ,device_fn=0x%x, where=0x%x, "
  85. "pci_addr=0x%p, type1=0x%p)\n",
  86. bus, device_fn, where, pci_addr, type1));
  87. if (!pbus->parent) /* No parent means peer PCI bus. */
  88. bus = 0;
  89. *type1 = (bus != 0);
  90. addr = (bus << 16) | (device_fn << 8) | where;
  91. addr |= hose->config_space_base;
  92. *pci_addr = addr;
  93. DBG_CFG(("mk_conf_addr: returning pci_addr 0x%lx\n", addr));
  94. return 0;
  95. }
  96. static int
  97. tsunami_read_config(struct pci_bus *bus, unsigned int devfn, int where,
  98. int size, u32 *value)
  99. {
  100. unsigned long addr;
  101. unsigned char type1;
  102. if (mk_conf_addr(bus, devfn, where, &addr, &type1))
  103. return PCIBIOS_DEVICE_NOT_FOUND;
  104. switch (size) {
  105. case 1:
  106. *value = __kernel_ldbu(*(vucp)addr);
  107. break;
  108. case 2:
  109. *value = __kernel_ldwu(*(vusp)addr);
  110. break;
  111. case 4:
  112. *value = *(vuip)addr;
  113. break;
  114. }
  115. return PCIBIOS_SUCCESSFUL;
  116. }
  117. static int
  118. tsunami_write_config(struct pci_bus *bus, unsigned int devfn, int where,
  119. int size, u32 value)
  120. {
  121. unsigned long addr;
  122. unsigned char type1;
  123. if (mk_conf_addr(bus, devfn, where, &addr, &type1))
  124. return PCIBIOS_DEVICE_NOT_FOUND;