1
2
3
4
5
6
7
8
9
10
11
12
13#include <linux/types.h>
14#include <linux/kernel.h>
15#include <linux/pci.h>
16#include <linux/init.h>
17#include <linux/ioport.h>
18#include <linux/errno.h>
19#include "pci-asb2305.h"
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34resource_size_t pcibios_align_resource(void *data, const struct resource *res,
35 resource_size_t size, resource_size_t align)
36{
37 resource_size_t start = res->start;
38
39#if 0
40 struct pci_dev *dev = data;
41
42 printk(KERN_DEBUG
43 "### PCIBIOS_ALIGN_RESOURCE(%s,,{%08lx-%08lx,%08lx},%lx)\n",
44 pci_name(dev),
45 res->start,
46 res->end,
47 res->flags,
48 size
49 );
50#endif
51
52 if ((res->flags & IORESOURCE_IO) && (start & 0x300))
53 start = (start + 0x3ff) & ~0x3ff;
54
55 return start;
56}
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91static void __init pcibios_allocate_bus_resources(struct list_head *bus_list)
92{
93 struct pci_bus *bus;
94 struct pci_dev *dev;
95 int idx;
96 struct resource *r;
97
98
99 list_for_each_entry(bus, bus_list, node) {
100 dev = bus->self;
101 if (dev) {
102 for (idx = PCI_BRIDGE_RESOURCES;
103 idx < PCI_NUM_RESOURCES;
104 idx++) {
105 r = &dev->resource[idx];
106 if (!r->flags)
107 continue;
108 if (!r->start ||
109 pci_claim_resource(dev, idx) < 0) {
110 printk(KERN_ERR "PCI:"
111 " Cannot allocate resource"
112 " region %d of bridge %s\n",
113 idx, pci_name(dev));
114
115
116
117
118 r->start = r->end = 0;
119 r->flags = 0;
120 }
121 }
122 }
123 pcibios_allocate_bus_resources(&bus->children);
124 }
125}
126
127static void __init pcibios_allocate_resources(int pass)
128{
129 struct pci_dev *dev = NULL;
130 int idx, disabled;
131 u16 command;
132 struct resource *r;
133
134 for_each_pci_dev(dev) {
135 pci_read_config_word(dev, PCI_COMMAND, &command);
136 for (idx = 0; idx < 6; idx++) {
137 r = &dev->resource[idx];
138 if (r->parent)
139 continue;
140 if (!r->start)
141 continue;
142 if (r->flags & IORESOURCE_IO)
143 disabled = !(command & PCI_COMMAND_IO);
144 else
145 disabled = !(command & PCI_COMMAND_MEMORY);
146 if (pass == disabled) {
147 DBG("PCI[%s]: Resource %08lx-%08lx"
148 " (f=%lx, d=%d, p=%d)\n",
149 pci_name(dev), r->start, r->end, r->flags,
150 disabled, pass);
151 if (pci_claim_resource(dev, idx) < 0) {
152 printk(KERN_ERR "PCI:"
153 " Cannot allocate resource"
154 " region %d of device %s\n",
155 idx, pci_name(dev));
156
157 r->end -= r->start;
158 r->start = 0;
159 }
160 }
161 }
162 if (!pass) {
163 r = &dev->resource[PCI_ROM_RESOURCE];
164 if (r->flags & IORESOURCE_ROM_ENABLE) {
165
166
167 u32 reg;
168 DBG("PCI: Switching off ROM of %s\n",
169 pci_name(dev));
170 r->flags &= ~IORESOURCE_ROM_ENABLE;
171 pci_read_config_dword(
172 dev, dev->rom_base_reg, ®);
173 pci_write_config_dword(
174 dev, dev->rom_base_reg,
175 reg & ~PCI_ROM_ADDRESS_ENABLE);
176 }
177 }
178 }
179}
180
181static int __init pcibios_assign_resources(void)
182{
183 struct pci_dev *dev = NULL;
184 struct resource *r;
185
186 if (!(pci_probe & PCI_ASSIGN_ROMS)) {
187
188
189
190 for_each_pci_dev(dev) {
191 r = &dev->resource[PCI_ROM_RESOURCE];
192 if (!r->flags || !r->start)
193 continue;
194 if (pci_claim_resource(dev, PCI_ROM_RESOURCE) < 0) {
195 r->end -= r->start;
196 r->start = 0;
197 }
198 }
199 }
200
201 pci_assign_unassigned_resources();
202
203 return 0;
204}
205
206fs_initcall(pcibios_assign_resources);
207
208void __init pcibios_resource_survey(void)
209{
210 DBG("PCI: Allocating resources\n");
211 pcibios_allocate_bus_resources(&pci_root_buses);
212 pcibios_allocate_resources(0);
213 pcibios_allocate_resources(1);
214}
215
216
217
218
219
220unsigned int pcibios_max_latency = 255;
221
222void pcibios_set_master(struct pci_dev *dev)
223{
224 u8 lat;
225
226 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &lat);
227
228 if (lat < 16)
229 lat = (64 <= pcibios_max_latency) ? 64 : pcibios_max_latency;
230 else if (lat > pcibios_max_latency)
231 lat = pcibios_max_latency;
232 else
233 return;
234
235 pci_write_config_byte(dev, PCI_LATENCY_TIMER, lat);
236}
237
238int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
239 enum pci_mmap_state mmap_state, int write_combine)
240{
241 unsigned long prot;
242
243
244
245
246 vma->vm_flags |= VM_LOCKED | VM_IO;
247
248 prot = pgprot_val(vma->vm_page_prot);
249 prot &= ~_PAGE_CACHE;
250 vma->vm_page_prot = __pgprot(prot);
251
252
253 if (io_remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
254 vma->vm_end - vma->vm_start,
255 vma->vm_page_prot))
256 return -EAGAIN;
257
258 return 0;
259}
260