Merge branch 'omap-for-v4.14/fixes' into omap-for-v4.15/fixes-v2
[sfrench/cifs-2.6.git] / arch / alpha / kernel / pci-noop.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  *      linux/arch/alpha/kernel/pci-noop.c
4  *
5  * Stub PCI interfaces for Jensen-specific kernels.
6  */
7
8 #include <linux/pci.h>
9 #include <linux/init.h>
10 #include <linux/bootmem.h>
11 #include <linux/gfp.h>
12 #include <linux/capability.h>
13 #include <linux/mm.h>
14 #include <linux/errno.h>
15 #include <linux/sched.h>
16 #include <linux/dma-mapping.h>
17 #include <linux/scatterlist.h>
18
19 #include "proto.h"
20
21
22 /*
23  * The PCI controller list.
24  */
25
26 struct pci_controller *hose_head, **hose_tail = &hose_head;
27 struct pci_controller *pci_isa_hose;
28
29
30 struct pci_controller * __init
31 alloc_pci_controller(void)
32 {
33         struct pci_controller *hose;
34
35         hose = alloc_bootmem(sizeof(*hose));
36
37         *hose_tail = hose;
38         hose_tail = &hose->next;
39
40         return hose;
41 }
42
43 struct resource * __init
44 alloc_resource(void)
45 {
46         return alloc_bootmem(sizeof(struct resource));
47 }
48
49 asmlinkage long
50 sys_pciconfig_iobase(long which, unsigned long bus, unsigned long dfn)
51 {
52         struct pci_controller *hose;
53
54         /* from hose or from bus.devfn */
55         if (which & IOBASE_FROM_HOSE) {
56                 for (hose = hose_head; hose; hose = hose->next) 
57                         if (hose->index == bus)
58                                 break;
59                 if (!hose)
60                         return -ENODEV;
61         } else {
62                 /* Special hook for ISA access.  */
63                 if (bus == 0 && dfn == 0)
64                         hose = pci_isa_hose;
65                 else
66                         return -ENODEV;
67         }
68
69         switch (which & ~IOBASE_FROM_HOSE) {
70         case IOBASE_HOSE:
71                 return hose->index;
72         case IOBASE_SPARSE_MEM:
73                 return hose->sparse_mem_base;
74         case IOBASE_DENSE_MEM:
75                 return hose->dense_mem_base;
76         case IOBASE_SPARSE_IO:
77                 return hose->sparse_io_base;
78         case IOBASE_DENSE_IO:
79                 return hose->dense_io_base;
80         case IOBASE_ROOT_BUS:
81                 return hose->bus->number;
82         }
83
84         return -EOPNOTSUPP;
85 }
86
87 asmlinkage long
88 sys_pciconfig_read(unsigned long bus, unsigned long dfn,
89                    unsigned long off, unsigned long len, void *buf)
90 {
91         if (!capable(CAP_SYS_ADMIN))
92                 return -EPERM;
93         else
94                 return -ENODEV;
95 }
96
97 asmlinkage long
98 sys_pciconfig_write(unsigned long bus, unsigned long dfn,
99                     unsigned long off, unsigned long len, void *buf)
100 {
101         if (!capable(CAP_SYS_ADMIN))
102                 return -EPERM;
103         else
104                 return -ENODEV;
105 }
106
107 static void *alpha_noop_alloc_coherent(struct device *dev, size_t size,
108                                        dma_addr_t *dma_handle, gfp_t gfp,
109                                        unsigned long attrs)
110 {
111         void *ret;
112
113         if (!dev || *dev->dma_mask >= 0xffffffffUL)
114                 gfp &= ~GFP_DMA;
115         ret = (void *)__get_free_pages(gfp, get_order(size));
116         if (ret) {
117                 memset(ret, 0, size);
118                 *dma_handle = virt_to_phys(ret);
119         }
120         return ret;
121 }
122
123 static int alpha_noop_supported(struct device *dev, u64 mask)
124 {
125         return mask < 0x00ffffffUL ? 0 : 1;
126 }
127
128 const struct dma_map_ops alpha_noop_ops = {
129         .alloc                  = alpha_noop_alloc_coherent,
130         .free                   = dma_noop_free_coherent,
131         .map_page               = dma_noop_map_page,
132         .map_sg                 = dma_noop_map_sg,
133         .mapping_error          = dma_noop_mapping_error,
134         .dma_supported          = alpha_noop_supported,
135 };
136
137 const struct dma_map_ops *dma_ops = &alpha_noop_ops;
138 EXPORT_SYMBOL(dma_ops);