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