]> nv-tegra.nvidia Code Review - linux-2.6.git/blob - arch/sparc/include/asm/sbus_64.h
sparc: Make SBUS DMA interfaces take struct device.
[linux-2.6.git] / arch / sparc / include / asm / sbus_64.h
1 /* sbus.h: Defines for the Sun SBus.
2  *
3  * Copyright (C) 1996, 1999, 2007 David S. Miller (davem@davemloft.net)
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 #include <linux/of_device.h>
12
13 #include <asm/oplib.h>
14 #include <asm/prom.h>
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
32 static inline unsigned long sbus_devaddr(int slotnum, unsigned long offset)
33 {
34   return (unsigned long) (SUN_SBUS_BVADDR+((slotnum)<<28)+(offset));
35 }
36
37 static inline int sbus_dev_slot(unsigned long dev_addr)
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 {
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;
54
55         struct resource resource[PROMREG_MAX];
56
57         struct linux_prom_registers reg_addrs[PROMREG_MAX];
58         int num_registers;
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 };
66 #define to_sbus_device(d) container_of(d, struct sbus_dev, ofdev.dev)
67
68 /* This struct describes the SBus(s) found on this machine. */
69 struct sbus_bus {
70         struct of_device        ofdev;
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;
81 };
82 #define to_sbus(d) container_of(d, struct sbus_bus, ofdev.dev)
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);
101 extern void sbus_fill_device_irq(struct sbus_dev *);
102
103 static inline void *sbus_alloc_consistent(struct device *dev , size_t size,
104                                           dma_addr_t *dma_handle)
105 {
106         return dma_alloc_coherent(dev, size, dma_handle, GFP_ATOMIC);
107 }
108
109 static inline void sbus_free_consistent(struct device *dev, size_t size,
110                                         void *vaddr, dma_addr_t dma_handle)
111 {
112         return dma_free_coherent(dev, size, vaddr, dma_handle);
113 }
114
115 #define SBUS_DMA_BIDIRECTIONAL  DMA_BIDIRECTIONAL
116 #define SBUS_DMA_TODEVICE       DMA_TO_DEVICE
117 #define SBUS_DMA_FROMDEVICE     DMA_FROM_DEVICE
118 #define SBUS_DMA_NONE           DMA_NONE
119
120 /* All the rest use streaming mode mappings. */
121 static inline dma_addr_t sbus_map_single(struct device *dev, void *ptr,
122                                          size_t size, int direction)
123 {
124         return dma_map_single(dev, ptr, size,
125                               (enum dma_data_direction) direction);
126 }
127
128 static inline void sbus_unmap_single(struct device *dev,
129                                      dma_addr_t dma_addr, size_t size,
130                                      int direction)
131 {
132         dma_unmap_single(dev, dma_addr, size,
133                          (enum dma_data_direction) direction);
134 }
135
136 static inline int sbus_map_sg(struct device *dev, struct scatterlist *sg,
137                               int nents, int direction)
138 {
139         return dma_map_sg(dev, sg, nents,
140                           (enum dma_data_direction) direction);
141 }
142
143 static inline void sbus_unmap_sg(struct device *dev, struct scatterlist *sg,
144                                  int nents, int direction)
145 {
146         dma_unmap_sg(dev, sg, nents,
147                      (enum dma_data_direction) direction);
148 }
149
150 /* Finally, allow explicit synchronization of streamable mappings. */
151 static inline void sbus_dma_sync_single_for_cpu(struct device *dev,
152                                                 dma_addr_t dma_handle,
153                                                 size_t size, int direction)
154 {
155         dma_sync_single_for_cpu(dev, dma_handle, size,
156                                 (enum dma_data_direction) direction);
157 }
158
159 static inline void sbus_dma_sync_single_for_device(struct device *dev,
160                                                    dma_addr_t dma_handle,
161                                                    size_t size, int direction)
162 {
163         /* No flushing needed to sync cpu writes to the device.  */
164 }
165
166 extern void sbus_arch_bus_ranges_init(struct device_node *, struct sbus_bus *);
167 extern void sbus_setup_iommu(struct sbus_bus *, struct device_node *);
168 extern void sbus_setup_arch_props(struct sbus_bus *, struct device_node *);
169 extern int sbus_arch_preinit(void);
170 extern void sbus_arch_postinit(void);
171
172 #endif /* !(_SPARC64_SBUS_H) */