alarmDataOperation.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. /*
  2. * linux/arch/alpha/kernel/core_titan.c
  3. *
  4. * Code common to all TITAN core logic chips.
  5. */
  6. #define __EXTERN_INLINE inline
  7. #include <asm/io.h>
  8. #include <asm/core_titan.h>
  9. #undef __EXTERN_INLINE
  10. #include <linux/module.h>
  11. #include <linux/types.h>
  12. #include <linux/pci.h>
  13. #include <linux/sched.h>
  14. #include <linux/init.h>
  15. #include <linux/vmalloc.h>
  16. #include <linux/bootmem.h>
  17. #include <asm/ptrace.h>
  18. #include <asm/smp.h>
  19. #include <asm/pgalloc.h>
  20. #include <asm/tlbflush.h>
  21. #include <asm/vga.h>
  22. #include "proto.h"
  23. #include "pci_impl.h"
  24. /* Save Titan configuration data as the console had it set up. */
  25. struct
  26. {
  27. unsigned long wsba[4];
  28. unsigned long wsm[4];
  29. unsigned long tba[4];
  30. } saved_config[4] __attribute__((common));
  31. /*
  32. * Is PChip 1 present? No need to query it more than once.
  33. */
  34. static int titan_pchip1_present;
  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. * Routines to access TIG registers.
  46. */
  47. static inline volatile unsigned long *
  48. mk_tig_addr(int offset)
  49. {
  50. return (volatile unsigned long *)(TITAN_TIG_SPACE + (offset << 6));
  51. }
  52. static inline u8
  53. titan_read_tig(int offset, u8 value)
  54. {
  55. volatile unsigned long *tig_addr = mk_tig_addr(offset);
  56. return (u8)(*tig_addr & 0xff);
  57. }
  58. static inline void
  59. titan_write_tig(int offset, u8 value)
  60. {
  61. volatile unsigned long *tig_addr = mk_tig_addr(offset);
  62. *tig_addr = (unsigned long)value;
  63. }
  64. /*
  65. * Given a bus, device, and function number, compute resulting
  66. * configuration space address
  67. * accordingly. It is therefore not safe to have concurrent
  68. * invocations to configuration space access routines, but there
  69. * really shouldn't be any need for this.
  70. *
  71. * Note that all config space accesses use Type 1 address format.
  72. *
  73. * Note also that type 1 is determined by non-zero bus number.
  74. *
  75. * Type 1:
  76. *
  77. * 3 3|3 3 2 2|2 2 2 2|2 2 2 2|1 1 1 1|1 1 1 1|1 1
  78. * 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
  79. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  80. * | | | | | | | | | | |B|B|B|B|B|B|B|B|D|D|D|D|D|F|F|F|R|R|R|R|R|R|0|1|
  81. * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  82. *
  83. * 31:24 reserved
  84. * 23:16 bus number (8 bits = 128 possible buses)
  85. * 15:11 Device number (5 bits)
  86. * 10:8 function number
  87. * 7:2 register number
  88. *
  89. * Notes:
  90. * The function number selects which function of a multi-function device
  91. * (e.g., SCSI and Ethernet).
  92. *
  93. * The register selects a DWORD (32 bit) register offset. Hence it
  94. * doesn't get shifted by 2 bits as we want to "drop" the bottom two
  95. * bits.
  96. */
  97. static int
  98. mk_conf_addr(struct pci_bus *pbus, unsigned int device_fn, int where,
  99. unsigned long *pci_addr, unsigned char *type1)
  100. {
  101. struct pci_controller *hose = pbus->sysdata;
  102. unsigned long addr;
  103. u8 bus = pbus->number;
  104. DBG_CFG(("mk_conf_addr(bus=%d ,device_fn=0x%x, where=0x%x, "
  105. "pci_addr=0x%p, type1=0x%p)\n",
  106. bus, device_fn, where, pci_addr, type1));
  107. if (!pbus->parent) /* No parent means peer PCI bus. */
  108. bus = 0;
  109. *type1 = (bus != 0);
  110. addr = (bus << 16) | (device_fn << 8) | where;
  111. addr |= hose->config_space_base;
  112. *pci_addr = addr;
  113. DBG_CFG(("mk_conf_addr: returning pci_addr 0x%lx\n", addr));
  114. return 0;
  115. }
  116. static int
  117. titan_read_config(struct pci_bus *bus, unsigned int devfn, int where,
  118. int size, u32 *value)
  119. {
  120. unsigned long addr;
  121. unsigned char type1;
  122. if (mk_conf_addr(bus, devfn, where, &addr, &type1))
  123. return PCIBIOS_DEVICE_NOT_FOUND;
  124. switch (size) {
  125. case 1:
  126. *value = __kernel_ldbu(*(vucp)addr);
  127. break;
  128. case 2:
  129. *value = __kernel_ldwu(*(vusp)addr);
  130. break;
  131. case 4:
  132. *value = *(vuip)addr;
  133. break;
  134. }
  135. return PCIBIOS_SUCCESSFUL;
  136. }
  137. static int
  138. titan_write_config(struct pci_bus *bus, unsigned int devfn, int where,
  139. int size, u32 value)
  140. {
  141. unsigned long addr;
  142. unsigned char type1;
  143. if (mk_conf_addr(bus, devfn, where, &addr, &type1))
  144. return PCIBIOS_DEVICE_NOT_FOUND;
  145. switch (size) {
  146. case 1:
  147. __kernel_stb(value, *(vucp)addr);
  148. mb();
  149. __kernel_ldbu(*(vucp)addr);
  150. break;
  151. case 2:
  152. __kernel_stw(value, *(vusp)addr);
  153. mb();
  154. __kernel_ldwu(*(vusp)addr);
  155. break;
  156. case 4:
  157. *(vuip)addr = value;
  158. mb();
  159. *(vuip)addr;
  160. break;
  161. }
  162. return PCIBIOS_SUCCESSFUL;
  163. }
  164. struct pci_ops titan_pci_ops =
  165. {
  166. .read = titan_read_config,
  167. .write = titan_write_config,
  168. };
  169. void
  170. titan_pci_tbi(struct pci_controller *hose, dma_addr_t start, dma_addr_t end)
  171. {
  172. titan_pachip *pachip =
  173. (hose->index & 1) ? TITAN_pachip1 : TITAN_pachip0;
  174. titan_pachip_port *port;
  175. volatile unsigned long *csr;
  176. unsigned long value;
  177. /* Get the right hose. */
  178. port = &pachip->g_port;
  179. if (hose->index & 2)
  180. port = &pachip->a_port;
  181. /* We can invalidate up to 8 tlb entries in a go. The flush
  182. matches against <31:16> in the pci address.
  183. Note that gtlbi* and atlbi* are in the same place in the g_port
  184. and a_port, respectively, so the g_port offset can be used
  185. even if hose is an a_port */
  186. csr = &port->port_specific.g.gtlbia.csr;
  187. if (((start ^ end) & 0xffff0000) == 0)
  188. csr = &port->port_specific.g.gtlbiv.csr;
  189. /* For TBIA, it doesn't matter what value we write. For TBI,
  190. it's the shifted tag bits. */
  191. value = (start & 0xffff0000) >> 12;
  192. wmb();
  193. *csr = value;
  194. mb();
  195. *csr;
  196. }
  197. static int
  198. titan_query_agp(titan_pachip_port *port)
  199. {
  200. union TPAchipPCTL pctl;
  201. /* set up APCTL */
  202. pctl.pctl_q_whole = port->pctl.csr;
  203. return pctl.pctl_r_bits.apctl_v_agp_present;
  204. }
  205. static void __init
  206. titan_init_one_pachip_port(titan_pachip_port *port, int index)
  207. {
  208. struct pci_controller *hose;
  209. hose = alloc_pci_controller();
  210. if (index == 0)
  211. pci_isa_hose = hose;
  212. hose->io_space = alloc_resource();
  213. hose->mem_space = alloc_resource();
  214. /*
  215. * This is for userland consumption. The 40-bit PIO bias that we
  216. * use in the kernel through KSEG doesn't work in the page table
  217. * based user mappings. (43-bit KSEG sign extends the physical
  218. * address from bit 40 to hit the I/O bit - mapped addresses don't).
  219. * So make sure we get the 43-bit PIO bias.
  220. */
  221. hose->sparse_mem_base = 0;
  222. hose->sparse_io_base = 0;
  223. hose->dense_mem_base
  224. = (TITAN_MEM(index) & 0xffffffffffUL) | 0x80000000000UL;
  225. hose->dense_io_base
  226. = (TITAN_IO(index) & 0xffffffffffUL) | 0x80000000000UL;
  227. hose->config_space_base = TITAN_CONF(index);
  228. hose->index = index;
  229. hose->io_space->start = TITAN_IO(index) - TITAN_IO_BIAS;
  230. hose->io_space->end = hose->io_space->start + TITAN_IO_SPACE - 1;
  231. hose->io_space->name = pci_io_names[index];
  232. hose->io_space->flags = IORESOURCE_IO;
  233. hose->mem_space->start = TITAN_MEM(index) - TITAN_MEM_BIAS;
  234. hose->mem_space->end = hose->mem_space->start + 0xffffffff;
  235. hose->mem_space->name = pci_mem_names[index];
  236. hose->mem_space->flags = IORESOURCE_MEM;
  237. if (request_resource(&ioport_resource, hose->io_space) < 0)
  238. printk(KERN_ERR "Failed to request IO on hose %d\n", index);
  239. if (request_resource(&iomem_resource, hose->mem_space) < 0)
  240. printk(KERN_ERR "Failed to request MEM on hose %d\n", index);
  241. /*
  242. * Save the existing PCI window translations. SRM will
  243. * need them when we go to reboot.
  244. */
  245. saved_config[index].wsba[0] = port->wsba[0].csr;
  246. saved_config[index].wsm[0] = port->wsm[0].csr;
  247. saved_config[index].tba[0] = port->tba[0].csr;
  248. saved_config[index].wsba[1] = port->wsba[1].csr;
  249. saved_config[index].wsm[1] = port->wsm[1].csr;
  250. saved_config[index].tba[1] = port->tba[1].csr;
  251. saved_config[index].wsba[2] = port->wsba[2].csr;
  252. saved_config[index].wsm[2] = port->wsm[2].csr;
  253. saved_config[index].tba[2] = port->tba[2].csr;
  254. saved_config[index].wsba[3] = port->wsba[3].csr;
  255. saved_config[index].wsm[3] = port->wsm[3].csr;
  256. saved_config[index].tba[3] = port->tba[3].csr;
  257. /*
  258. * Set up the PCI to main memory translation windows.
  259. *
  260. * Note: Window 3 on Titan is Scatter-Gather ONLY.
  261. *
  262. * Window 0 is scatter-gather 8MB at 8MB (for isa)
  263. * Window 1 is direct access 1GB at 2GB
  264. * Window 2 is scatter-gather 1GB at 3GB
  265. */
  266. hose->sg_isa = iommu_arena_new(hose, 0x00800000, 0x00800000, 0);
  267. hose->sg_isa->align_entry = 8; /* 64KB for ISA */
  268. hose->sg_pci = iommu_arena_new(hose, 0xc0000000, 0x40000000, 0);
  269. hose->sg_pci->align_entry = 4; /* Titan caches 4 PTEs at a time */
  270. port->wsba[0].csr = hose->sg_isa->dma_base | 3;
  271. port->wsm[0].csr = (hose->sg_isa->size - 1) & 0xfff00000;
  272. port->tba[0].csr = virt_to_phys(hose->sg_isa->ptes);
  273. port->wsba[1].csr = __direct_map_base | 1;
  274. port->wsm[1].csr = (__direct_map_size - 1) & 0xfff00000;
  275. port->tba[1].csr = 0;
  276. port->wsba[2].csr = hose->sg_pci->dma_base | 3;
  277. port->wsm[2].csr = (hose->sg_pci->size - 1) & 0xfff00000;
  278. port->tba[2].csr = virt_to_phys(hose->sg_pci->ptes);
  279. port->wsba[3].csr = 0;
  280. /* Enable the Monster Window to make DAC pci64 possible. */
  281. port->pctl.csr |= pctl_m_mwin;
  282. /*
  283. * If it's an AGP port, initialize agplastwr.
  284. */
  285. if (titan_query_agp(port))
  286. port->port_specific.a.agplastwr.csr = __direct_map_base;
  287. titan_pci_tbi(hose, 0, -1);
  288. }
  289. static void __init
  290. titan_init_pachips(titan_pachip *pachip0, titan_pachip *pachip1)
  291. {
  292. titan_pchip1_present = TITAN_cchip->csc.csr & 1L<<14;
  293. /* Init the ports in hose order... */
  294. titan_init_one_pachip_port(&pachip0->g_port, 0); /* hose 0 */
  295. if (titan_pchip1_present)
  296. titan_init_one_pachip_port(&pachip1->g_port, 1);/* hose 1 */
  297. titan_init_one_pachip_port(&pachip0->a_port, 2); /* hose 2 */
  298. if (titan_pchip1_present)