Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ieee1394...
[sfrench/cifs-2.6.git] / arch / alpha / kernel / pci-noop.c
1 /*
2  *      linux/arch/alpha/kernel/pci-noop.c
3  *
4  * Stub PCI interfaces for Jensen-specific kernels.
5  */
6
7 #include <linux/pci.h>
8 #include <linux/init.h>
9 #include <linux/bootmem.h>
10 #include <linux/capability.h>
11 #include <linux/mm.h>
12 #include <linux/errno.h>
13 #include <linux/sched.h>
14 #include <linux/dma-mapping.h>
15 #include <linux/scatterlist.h>
16
17 #include "proto.h"
18
19
20 /*
21  * The PCI controller list.
22  */
23
24 struct pci_controller *hose_head, **hose_tail = &hose_head;
25 struct pci_controller *pci_isa_hose;
26
27
28 struct pci_controller * __init
29 alloc_pci_controller(void)
30 {
31         struct pci_controller *hose;
32
33         hose = alloc_bootmem(sizeof(*hose));
34
35         *hose_tail = hose;
36         hose_tail = &hose->next;
37
38         return hose;
39 }
40
41 struct resource * __init
42 alloc_resource(void)
43 {
44         struct resource *res;
45
46         res = alloc_bootmem(sizeof(*res));
47
48         return res;
49 }
50
51 asmlinkage long
52 sys_pciconfig_iobase(long which, unsigned long bus, unsigned long dfn)
53 {
54         struct pci_controller *hose;
55
56         /* from hose or from bus.devfn */
57         if (which & IOBASE_FROM_HOSE) {
58                 for (hose = hose_head; hose; hose = hose->next) 
59                         if (hose->index == bus)
60                                 break;
61                 if (!hose)
62                         return -ENODEV;
63         } else {
64                 /* Special hook for ISA access.  */
65                 if (bus == 0 && dfn == 0)
66                         hose = pci_isa_hose;
67                 else
68                         return -ENODEV;
69         }
70
71         switch (which & ~IOBASE_FROM_HOSE) {
72         case IOBASE_HOSE:
73                 return hose->index;
74         case IOBASE_SPARSE_MEM:
75                 return hose->sparse_mem_base;
76         case IOBASE_DENSE_MEM:
77                 return hose->dense_mem_base;
78         case IOBASE_SPARSE_IO:
79                 return hose->sparse_io_base;
80         case IOBASE_DENSE_IO:
81                 return hose->dense_io_base;
82         case IOBASE_ROOT_BUS:
83                 return hose->bus->number;
84         }
85
86         return -EOPNOTSUPP;
87 }
88
89 asmlinkage long
90 sys_pciconfig_read(unsigned long bus, unsigned long dfn,
91                    unsigned long off, unsigned long len, void *buf)
92 {
93         if (!capable(CAP_SYS_ADMIN))
94                 return -EPERM;
95         else
96                 return -ENODEV;
97 }
98
99 asmlinkage long
100 sys_pciconfig_write(unsigned long bus, unsigned long dfn,
101                     unsigned long off, unsigned long len, void *buf)
102 {
103         if (!capable(CAP_SYS_ADMIN))
104                 return -EPERM;
105         else
106                 return -ENODEV;
107 }
108
109 static void *alpha_noop_alloc_coherent(struct device *dev, size_t size,
110                                        dma_addr_t *dma_handle, gfp_t gfp)
111 {
112         void *ret;
113
114         if (!dev || *dev->dma_mask >= 0xffffffffUL)
115                 gfp &= ~GFP_DMA;
116         ret = (void *)__get_free_pages(gfp, get_order(size));
117         if (ret) {
118                 memset(ret, 0, size);
119                 *dma_handle = virt_to_phys(ret);
120         }
121         return ret;
122 }
123
124 static void alpha_noop_free_coherent(struct device *dev, size_t size,
125                                      void *cpu_addr, dma_addr_t dma_addr)
126 {
127         free_pages((unsigned long)cpu_addr, get_order(size));
128 }
129
130 static dma_addr_t alpha_noop_map_page(struct device *dev, struct page *page,
131                                       unsigned long offset, size_t size,
132                                       enum dma_data_direction dir,
133                                       struct dma_attrs *attrs)
134 {
135         return page_to_pa(page) + offset;
136 }
137
138 static int alpha_noop_map_sg(struct device *dev, struct scatterlist *sgl, int nents,
139                              enum dma_data_direction dir, struct dma_attrs *attrs)
140 {
141         int i;
142         struct scatterlist *sg;
143
144         for_each_sg(sgl, sg, nents, i) {
145                 void *va;
146
147                 BUG_ON(!sg_page(sg));
148                 va = sg_virt(sg);
149                 sg_dma_address(sg) = (dma_addr_t)virt_to_phys(va);
150                 sg_dma_len(sg) = sg->length;
151         }
152
153         return nents;
154 }
155
156 static int alpha_noop_mapping_error(struct device *dev, dma_addr_t dma_addr)
157 {
158         return 0;
159 }
160
161 static int alpha_noop_supported(struct device *dev, u64 mask)
162 {
163         return mask < 0x00ffffffUL ? 0 : 1;
164 }
165
166 static int alpha_noop_set_mask(struct device *dev, u64 mask)
167 {
168         if (!dev->dma_mask || !dma_supported(dev, mask))
169                 return -EIO;
170
171         *dev->dma_mask = mask;
172         return 0;
173 }
174
175 struct dma_map_ops alpha_noop_ops = {
176         .alloc_coherent         = alpha_noop_alloc_coherent,
177         .free_coherent          = alpha_noop_free_coherent,
178         .map_page               = alpha_noop_map_page,
179         .map_sg                 = alpha_noop_map_sg,
180         .mapping_error          = alpha_noop_mapping_error,
181         .dma_supported          = alpha_noop_supported,
182         .set_dma_mask           = alpha_noop_set_mask,
183 };
184
185 struct dma_map_ops *dma_ops = &alpha_noop_ops;
186 EXPORT_SYMBOL(dma_ops);
187
188 void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen)
189 {
190         return NULL;
191 }
192
193 void pci_iounmap(struct pci_dev *dev, void __iomem * addr)
194 {
195 }
196
197 EXPORT_SYMBOL(pci_iomap);
198 EXPORT_SYMBOL(pci_iounmap);