sbus.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /* sbus.h: Defines for the Sun SBus.
  2. *
  3. * Copyright (C) 1996, 1999, 2007 David S. Miller (davem@davemloft.net)
  4. */
  5. #ifndef _SPARC64_SBUS_H
  6. #define _SPARC64_SBUS_H
  7. #include <linux/dma-mapping.h>
  8. #include <linux/ioport.h>
  9. #include <asm/oplib.h>
  10. #include <asm/prom.h>
  11. #include <asm/of_device.h>
  12. #include <asm/iommu.h>
  13. #include <asm/scatterlist.h>
  14. /* We scan which devices are on the SBus using the PROM node device
  15. * tree. SBus devices are described in two different ways. You can
  16. * either get an absolute address at which to access the device, or
  17. * you can get a SBus 'slot' number and an offset within that slot.
  18. */
  19. /* The base address at which to calculate device OBIO addresses. */
  20. #define SUN_SBUS_BVADDR 0x00000000
  21. #define SBUS_OFF_MASK 0x0fffffff
  22. /* These routines are used to calculate device address from slot
  23. * numbers + offsets, and vice versa.
  24. */
  25. static __inline__ unsigned long sbus_devaddr(int slotnum, unsigned long offset)
  26. {
  27. return (unsigned long) (SUN_SBUS_BVADDR+((slotnum)<<28)+(offset));
  28. }
  29. static __inline__ int sbus_dev_slot(unsigned long dev_addr)
  30. {
  31. return (int) (((dev_addr)-SUN_SBUS_BVADDR)>>28);
  32. }
  33. struct sbus_bus;
  34. /* Linux SBUS device tables */
  35. struct sbus_dev {
  36. struct of_device ofdev;
  37. struct sbus_bus *bus;
  38. struct sbus_dev *next;
  39. struct sbus_dev *child;
  40. struct sbus_dev *parent;
  41. int prom_node;
  42. char prom_name[64];
  43. int slot;
  44. struct resource resource[PROMREG_MAX];
  45. struct linux_prom_registers reg_addrs[PROMREG_MAX];
  46. int num_registers;
  47. struct linux_prom_ranges device_ranges[PROMREG_MAX];
  48. int num_device_ranges;
  49. unsigned int irqs[4];
  50. int num_irqs;
  51. };
  52. #define to_sbus_device(d) container_of(d, struct sbus_dev, ofdev.dev)
  53. /* This struct describes the SBus(s) found on this machine. */
  54. struct sbus_bus {
  55. struct of_device ofdev;
  56. struct sbus_dev *devices; /* Tree of SBUS devices */
  57. struct sbus_bus *next; /* Next SBUS in system */
  58. int prom_node; /* OBP node of SBUS */
  59. char prom_name[64]; /* Usually "sbus" or "sbi" */
  60. int clock_freq;
  61. struct linux_prom_ranges sbus_ranges[PROMREG_MAX];
  62. int num_sbus_ranges;
  63. int portid;
  64. };
  65. #define to_sbus(d) container_of(d, struct sbus_bus, ofdev.dev)
  66. extern struct sbus_bus *sbus_root;
  67. /* Device probing routines could find these handy */
  68. #define for_each_sbus(bus) \
  69. for((bus) = sbus_root; (bus); (bus)=(bus)->next)
  70. #define for_each_sbusdev(device, bus) \
  71. for((device) = (bus)->devices; (device); (device)=(device)->next)
  72. #define for_all_sbusdev(device, bus) \
  73. for ((bus) = sbus_root; (bus); (bus) = (bus)->next) \
  74. for ((device) = (bus)->devices; (device); (device) = (device)->next)
  75. /* Driver DVMA interfaces. */
  76. #define sbus_can_dma_64bit(sdev) (1)
  77. #define sbus_can_burst64(sdev) (1)
  78. extern void sbus_set_sbus64(struct sbus_dev *, int);
  79. extern void sbus_fill_device_irq(struct sbus_dev *);
  80. static inline void *sbus_alloc_consistent(struct sbus_dev *sdev , size_t size,
  81. dma_addr_t *dma_handle)
  82. {
  83. return dma_alloc_coherent(&sdev->ofdev.dev, size,
  84. dma_handle, GFP_ATOMIC);
  85. }
  86. static inline void sbus_free_consistent(struct sbus_dev *sdev, size_t size,
  87. void *vaddr, dma_addr_t dma_handle)
  88. {
  89. return dma_free_coherent(&sdev->ofdev.dev, size, vaddr, dma_handle);
  90. }
  91. #define SBUS_DMA_BIDIRECTIONAL DMA_BIDIRECTIONAL
  92. #define SBUS_DMA_TODEVICE DMA_TO_DEVICE
  93. #define SBUS_DMA_FROMDEVICE DMA_FROM_DEVICE
  94. #define SBUS_DMA_NONE DMA_NONE
  95. /* All the rest use streaming mode mappings. */
  96. static inline dma_addr_t sbus_map_single(struct sbus_dev *sdev, void *ptr,
  97. size_t size, int direction)
  98. {
  99. return dma_map_single(&sdev->ofdev.dev, ptr, size,
  100. (enum dma_data_direction) direction);
  101. }
  102. static inline void sbus_unmap_single(struct sbus_dev *sdev,
  103. dma_addr_t dma_addr, size_t size,
  104. int direction)
  105. {
  106. dma_unmap_single(&sdev->ofdev.dev, dma_addr, size,
  107. (enum dma_data_direction) direction);
  108. }
  109. static inline int sbus_map_sg(struct sbus_dev *sdev, struct scatterlist *sg,
  110. int nents, int direction)
  111. {
  112. return dma_map_sg(&sdev->ofdev.dev, sg, nents,
  113. (enum dma_data_direction) direction);
  114. }
  115. static inline void sbus_unmap_sg(struct sbus_dev *sdev, struct scatterlist *sg,
  116. int nents, int direction)
  117. {
  118. dma_unmap_sg(&sdev->ofdev.dev, sg, nents,
  119. (enum dma_data_direction) direction);
  120. }
  121. /* Finally, allow explicit synchronization of streamable mappings. */
  122. static inline void sbus_dma_sync_single_for_cpu(struct sbus_dev *sdev,
  123. dma_addr_t dma_handle,
  124. size_t size, int direction)
  125. {
  126. dma_sync_single_for_cpu(&sdev->ofdev.dev, dma_handle, size,
  127. (enum dma_data_direction) direction);
  128. }
  129. #define sbus_dma_sync_single sbus_dma_sync_single_for_cpu
  130. static inline void sbus_dma_sync_single_for_device(struct sbus_dev *sdev,
  131. dma_addr_t dma_handle,
  132. size_t size, int direction)
  133. {
  134. /* No flushing needed to sync cpu writes to the device. */
  135. }
  136. static inline void sbus_dma_sync_sg_for_cpu(struct sbus_dev *sdev,
  137. struct scatterlist *sg,
  138. int nents, int direction)
  139. {
  140. dma_sync_sg_for_cpu(&sdev->ofdev.dev, sg, nents,
  141. (enum dma_data_direction) direction);
  142. }
  143. #define sbus_dma_sync_sg sbus_dma_sync_sg_for_cpu
  144. static inline void sbus_dma_sync_sg_for_device(struct sbus_dev *sdev,
  145. struct scatterlist *sg,
  146. int nents, int direction)
  147. {
  148. /* No flushing needed to sync cpu writes to the device. */
  149. }
  150. extern void sbus_arch_bus_ranges_init(struct device_node *, struct sbus_bus *);
  151. extern void sbus_setup_iommu(struct sbus_bus *, struct device_node *);
  152. extern void sbus_setup_arch_props(struct sbus_bus *, struct device_node *);
  153. extern int sbus_arch_preinit(void);
  154. extern void sbus_arch_postinit(void);
  155. #endif /* !(_SPARC64_SBUS_H) */