ARM: mmp: fix potential NULL dereference
[linux/fpc-iii.git] / arch / alpha / kernel / pci-noop.c
blobdf24b76f92461a5df780059eea1488e3b50945e7
1 /*
2 * linux/arch/alpha/kernel/pci-noop.c
4 * Stub PCI interfaces for Jensen-specific kernels.
5 */
7 #include <linux/pci.h>
8 #include <linux/init.h>
9 #include <linux/bootmem.h>
10 #include <linux/gfp.h>
11 #include <linux/capability.h>
12 #include <linux/mm.h>
13 #include <linux/errno.h>
14 #include <linux/sched.h>
15 #include <linux/dma-mapping.h>
16 #include <linux/scatterlist.h>
18 #include "proto.h"
22 * The PCI controller list.
25 struct pci_controller *hose_head, **hose_tail = &hose_head;
26 struct pci_controller *pci_isa_hose;
29 struct pci_controller * __init
30 alloc_pci_controller(void)
32 struct pci_controller *hose;
34 hose = alloc_bootmem(sizeof(*hose));
36 *hose_tail = hose;
37 hose_tail = &hose->next;
39 return hose;
42 struct resource * __init
43 alloc_resource(void)
45 struct resource *res;
47 res = alloc_bootmem(sizeof(*res));
49 return res;
52 asmlinkage long
53 sys_pciconfig_iobase(long which, unsigned long bus, unsigned long dfn)
55 struct pci_controller *hose;
57 /* from hose or from bus.devfn */
58 if (which & IOBASE_FROM_HOSE) {
59 for (hose = hose_head; hose; hose = hose->next)
60 if (hose->index == bus)
61 break;
62 if (!hose)
63 return -ENODEV;
64 } else {
65 /* Special hook for ISA access. */
66 if (bus == 0 && dfn == 0)
67 hose = pci_isa_hose;
68 else
69 return -ENODEV;
72 switch (which & ~IOBASE_FROM_HOSE) {
73 case IOBASE_HOSE:
74 return hose->index;
75 case IOBASE_SPARSE_MEM:
76 return hose->sparse_mem_base;
77 case IOBASE_DENSE_MEM:
78 return hose->dense_mem_base;
79 case IOBASE_SPARSE_IO:
80 return hose->sparse_io_base;
81 case IOBASE_DENSE_IO:
82 return hose->dense_io_base;
83 case IOBASE_ROOT_BUS:
84 return hose->bus->number;
87 return -EOPNOTSUPP;
90 asmlinkage long
91 sys_pciconfig_read(unsigned long bus, unsigned long dfn,
92 unsigned long off, unsigned long len, void *buf)
94 if (!capable(CAP_SYS_ADMIN))
95 return -EPERM;
96 else
97 return -ENODEV;
100 asmlinkage long
101 sys_pciconfig_write(unsigned long bus, unsigned long dfn,
102 unsigned long off, unsigned long len, void *buf)
104 if (!capable(CAP_SYS_ADMIN))
105 return -EPERM;
106 else
107 return -ENODEV;
110 static void *alpha_noop_alloc_coherent(struct device *dev, size_t size,
111 dma_addr_t *dma_handle, gfp_t gfp,
112 struct dma_attrs *attrs)
114 void *ret;
116 if (!dev || *dev->dma_mask >= 0xffffffffUL)
117 gfp &= ~GFP_DMA;
118 ret = (void *)__get_free_pages(gfp, get_order(size));
119 if (ret) {
120 memset(ret, 0, size);
121 *dma_handle = virt_to_phys(ret);
123 return ret;
126 static void alpha_noop_free_coherent(struct device *dev, size_t size,
127 void *cpu_addr, dma_addr_t dma_addr,
128 struct dma_attrs *attrs)
130 free_pages((unsigned long)cpu_addr, get_order(size));
133 static dma_addr_t alpha_noop_map_page(struct device *dev, struct page *page,
134 unsigned long offset, size_t size,
135 enum dma_data_direction dir,
136 struct dma_attrs *attrs)
138 return page_to_pa(page) + offset;
141 static int alpha_noop_map_sg(struct device *dev, struct scatterlist *sgl, int nents,
142 enum dma_data_direction dir, struct dma_attrs *attrs)
144 int i;
145 struct scatterlist *sg;
147 for_each_sg(sgl, sg, nents, i) {
148 void *va;
150 BUG_ON(!sg_page(sg));
151 va = sg_virt(sg);
152 sg_dma_address(sg) = (dma_addr_t)virt_to_phys(va);
153 sg_dma_len(sg) = sg->length;
156 return nents;
159 static int alpha_noop_mapping_error(struct device *dev, dma_addr_t dma_addr)
161 return 0;
164 static int alpha_noop_supported(struct device *dev, u64 mask)
166 return mask < 0x00ffffffUL ? 0 : 1;
169 static int alpha_noop_set_mask(struct device *dev, u64 mask)
171 if (!dev->dma_mask || !dma_supported(dev, mask))
172 return -EIO;
174 *dev->dma_mask = mask;
175 return 0;
178 struct dma_map_ops alpha_noop_ops = {
179 .alloc = alpha_noop_alloc_coherent,
180 .free = alpha_noop_free_coherent,
181 .map_page = alpha_noop_map_page,
182 .map_sg = alpha_noop_map_sg,
183 .mapping_error = alpha_noop_mapping_error,
184 .dma_supported = alpha_noop_supported,
185 .set_dma_mask = alpha_noop_set_mask,
188 struct dma_map_ops *dma_ops = &alpha_noop_ops;
189 EXPORT_SYMBOL(dma_ops);