Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
* Support PCI/PCIe on PowerNV platforms
*
* Copyright 2011 Benjamin Herrenschmidt, IBM Corp.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#define DEBUG
#include <linux/kernel.h>
#include <linux/pci.h>
#include <linux/delay.h>
#include <linux/string.h>
#include <linux/init.h>
#include <linux/bootmem.h>
#include <linux/irq.h>
#include <linux/io.h>
#include <linux/msi.h>
#include <asm/sections.h>
#include <asm/io.h>
#include <asm/prom.h>
#include <asm/pci-bridge.h>
#include <asm/machdep.h>
#include <asm/ppc-pci.h>
#include <asm/opal.h>
#include <asm/iommu.h>
#include <asm/tce.h>
#include <asm/abs_addr.h>
#include "powernv.h"
#include "pci.h"
struct resource_wrap {
struct list_head link;
resource_size_t size;
resource_size_t align;
struct pci_dev *dev; /* Set if it's a device */
struct pci_bus *bus; /* Set if it's a bridge */
};
static int __pe_printk(const char *level, const struct pnv_ioda_pe *pe,
struct va_format *vaf)
{
char pfix[32];
if (pe->pdev)
strlcpy(pfix, dev_name(&pe->pdev->dev), sizeof(pfix));
else
sprintf(pfix, "%04x:%02x ",
pci_domain_nr(pe->pbus), pe->pbus->number);
return printk("pci %s%s: [PE# %.3d] %pV", level, pfix, pe->pe_number, vaf);
}
#define define_pe_printk_level(func, kern_level) \
static int func(const struct pnv_ioda_pe *pe, const char *fmt, ...) \
{ \
struct va_format vaf; \
va_list args; \
int r; \
\
va_start(args, fmt); \
\
vaf.fmt = fmt; \
vaf.va = &args; \
\
r = __pe_printk(kern_level, pe, &vaf); \
va_end(args); \
\
return r; \
} \
define_pe_printk_level(pe_err, KERN_ERR);
define_pe_printk_level(pe_warn, KERN_WARNING);
define_pe_printk_level(pe_info, KERN_INFO);
/* Calculate resource usage & alignment requirement of a single
* device. This will also assign all resources within the device
* for a given type starting at 0 for the biggest one and then
* assigning in decreasing order of size.
*/
static void __devinit pnv_ioda_calc_dev(struct pci_dev *dev, unsigned int flags,
resource_size_t *size,
resource_size_t *align)
{
resource_size_t start;
struct resource *r;
int i;
pr_devel(" -> CDR %s\n", pci_name(dev));
*size = *align = 0;
/* Clear the resources out and mark them all unset */
for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
r = &dev->resource[i];
if (!(r->flags & flags))
continue;
if (r->start) {
r->end -= r->start;
r->start = 0;
}
r->flags |= IORESOURCE_UNSET;
}
/* We currently keep all memory resources together, we
* will handle prefetch & 64-bit separately in the future
* but for now we stick everybody in M32
*/
start = 0;
for (;;) {
resource_size_t max_size = 0;
int max_no = -1;
/* Find next biggest resource */
for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
r = &dev->resource[i];
if (!(r->flags & IORESOURCE_UNSET) ||
!(r->flags & flags))
continue;
if (resource_size(r) > max_size) {
max_size = resource_size(r);
max_no = i;
}
}
if (max_no < 0)
break;
r = &dev->resource[max_no];
if (max_size > *align)
*align = max_size;
*size += max_size;
r->start = start;
start += max_size;
r->end = r->start + max_size - 1;
r->flags &= ~IORESOURCE_UNSET;
pr_devel(" -> R%d %016llx..%016llx\n",
max_no, r->start, r->end);
}
pr_devel(" <- CDR %s size=%llx align=%llx\n",
pci_name(dev), *size, *align);
}
/* Allocate a resource "wrap" for a given device or bridge and
* insert it at the right position in the sorted list
*/
static void __devinit pnv_ioda_add_wrap(struct list_head *list,
struct pci_bus *bus,
struct pci_dev *dev,
resource_size_t size,
resource_size_t align)
{
struct resource_wrap *w1, *w = kzalloc(sizeof(*w), GFP_KERNEL);
w->size = size;
w->align = align;
w->dev = dev;
w->bus = bus;
list_for_each_entry(w1, list, link) {
if (w1->align < align) {
list_add_tail(&w->link, &w1->link);
return;
}
}
list_add_tail(&w->link, list);
}
/* Offset device resources of a given type */
static void __devinit pnv_ioda_offset_dev(struct pci_dev *dev,
unsigned int flags,
resource_size_t offset)
{
struct resource *r;
int i;
pr_devel(" -> ODR %s [%x] +%016llx\n", pci_name(dev), flags, offset);
for (i = 0; i <= PCI_ROM_RESOURCE; i++) {
r = &dev->resource[i];
if (r->flags & flags) {
dev->resource[i].start += offset;
dev->resource[i].end += offset;
}
}
pr_devel(" <- ODR %s [%x] +%016llx\n", pci_name(dev), flags, offset);
}
/* Offset bus resources (& all children) of a given type */
static void __devinit pnv_ioda_offset_bus(struct pci_bus *bus,
unsigned int flags,
resource_size_t offset)
{
struct resource *r;
struct pci_dev *dev;
Loading
Loading full blame...