summaryrefslogtreecommitdiffstats
path: root/arch/arm/kernel/dec21285.c
blob: 6a4988b152b389466adea60066ec7bb40dbf321d (plain)
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/*
 * arch/arm/kernel/dec21285.c: PCI functions for DC21285
 *
 * Copyright (C) 1998-1999 Russell King, Phil Blundell
 */
#include <linux/config.h>
#include <linux/sched.h>
#include <linux/kernel.h>
#include <linux/pci.h>
#include <linux/ptrace.h>
#include <linux/interrupt.h>
#include <linux/mm.h>
#include <linux/init.h>
#include <linux/ioport.h>

#include <asm/irq.h>
#include <asm/system.h>
#include <asm/hardware.h>

#define MAX_SLOTS		21

extern void pcibios_fixup_ebsa285(struct pci_dev *dev);
extern void pcibios_init_ebsa285(void);

int
pcibios_present(void)
{
	return 1;
}

static unsigned long
pcibios_base_address(unsigned char bus, unsigned char dev_fn)
{
	if (bus == 0) {
		int slot = PCI_SLOT(dev_fn);
		
		if (slot < MAX_SLOTS)
			return PCICFG0_BASE + 0xc00000 +
				(slot << 11) + (PCI_FUNC(dev_fn) << 8);
		else
			return 0;
	} else
		return PCICFG1_BASE | (bus << 16) | (dev_fn << 8);
}

int
pcibios_read_config_byte(unsigned char bus, unsigned char dev_fn,
			 unsigned char where, unsigned char *val)
{
	unsigned long addr = pcibios_base_address(bus, dev_fn);
	unsigned char v;

	if (addr)
		__asm__("ldr%?b	%0, [%1, %2]"
			: "=r" (v)
			: "r" (addr), "r" (where));
	else
		v = 0xff;
	*val = v;
	return PCIBIOS_SUCCESSFUL;
}

int
pcibios_read_config_word(unsigned char bus, unsigned char dev_fn,
			 unsigned char where, unsigned short *val)
{
	unsigned long addr = pcibios_base_address(bus, dev_fn);
	unsigned short v;

	if (addr)
		__asm__("ldr%?h	%0, [%1, %2]"
			: "=r" (v)
			: "r" (addr), "r" (where));
	else
		v = 0xffff;
	*val = v;
	return PCIBIOS_SUCCESSFUL;
}

int
pcibios_read_config_dword(unsigned char bus, unsigned char dev_fn,
			  unsigned char where, unsigned int *val)
{
	unsigned long addr = pcibios_base_address(bus, dev_fn);
	unsigned int v;

	if (addr)
		__asm__("ldr%?	%0, [%1, %2]"
			: "=r" (v)
			: "r" (addr), "r" (where));
	else
		v = 0xffffffff;
	*val = v;
	return PCIBIOS_SUCCESSFUL;
}

int
pcibios_write_config_byte(unsigned char bus, unsigned char dev_fn,
			  unsigned char where, unsigned char val)
{
	unsigned long addr = pcibios_base_address(bus, dev_fn);

	if (addr)
		__asm__("str%?b	%0, [%1, %2]"
			: : "r" (val), "r" (addr), "r" (where));
	return PCIBIOS_SUCCESSFUL;
}

int
pcibios_write_config_word(unsigned char bus, unsigned char dev_fn,
			  unsigned char where, unsigned short val)
{
	unsigned long addr = pcibios_base_address(bus, dev_fn);

	if (addr)
		__asm__("str%?h	%0, [%1, %2]"
			: : "r" (val), "r" (addr), "r" (where));
	return PCIBIOS_SUCCESSFUL;
}

int
pcibios_write_config_dword(unsigned char bus, unsigned char dev_fn,
			   unsigned char where, unsigned int val)
{
	unsigned long addr = pcibios_base_address(bus, dev_fn);

	if (addr)
		__asm__("str%?	%0, [%1, %2]"
			: : "r" (val), "r" (addr), "r" (where));
	return PCIBIOS_SUCCESSFUL;
}

void __init pci_set_cmd(struct pci_dev *dev, unsigned short clear, unsigned short set)
{
	unsigned short cmd;

	pci_read_config_word(dev, PCI_COMMAND, &cmd);
	cmd = (cmd & ~clear) | set;
	pci_write_config_word(dev, PCI_COMMAND, cmd);
}

void __init pci_set_base_addr(struct pci_dev *dev, int idx, unsigned int addr)
{
	int reg = PCI_BASE_ADDRESS_0 + (idx << 2);

	pci_write_config_dword(dev, reg, addr);
	pci_read_config_dword(dev, reg, &addr);

	dev->base_address[idx] = addr;
}

void __init pcibios_fixup(void)
{
	struct pci_dev *dev;

	for (dev = pci_devices; dev; dev = dev->next) {
		pcibios_fixup_ebsa285(dev);

		pcibios_write_config_byte(dev->bus->number, dev->devfn,
					  PCI_INTERRUPT_LINE, dev->irq);

		printk(KERN_DEBUG
		       "PCI: %02x:%02x [%04x/%04x] on irq %d\n",
			dev->bus->number, dev->devfn,
			dev->vendor, dev->device, dev->irq);
	}

	hw_init();
}

void __init pcibios_init(void)
{
	unsigned int mem_size = (unsigned int)high_memory - PAGE_OFFSET;
	unsigned long cntl;

	*CSR_SDRAMBASEMASK    = (mem_size - 1) & 0x0ffc0000;
	*CSR_SDRAMBASEOFFSET  = 0;
	*CSR_ROMBASEMASK      = 0x80000000;
	*CSR_CSRBASEMASK      = 0;
	*CSR_CSRBASEOFFSET    = 0;
	*CSR_PCIADDR_EXTN     = 0;

#ifdef CONFIG_HOST_FOOTBRIDGE
	/*
	 * Against my better judgement, Philip Blundell still seems
	 * to be saying that we should initialise the PCI stuff here
	 * when the PCI_CFN bit is not set, dispite my comment below,
	 * which he decided to remove.  If it is not set, then
	 * the card is in add-in mode, and we're in a machine where
	 * the bus is set up by 'others'.
	 *
	 * We should therefore not mess about with the mapping in
	 * anyway, and we should not be using the virt_to_bus functions
	 * that exist in the HOST architecture mode (since they assume
	 * a fixed mapping).
	 *
	 * Instead, you should be using ADDIN mode, which allows for
	 * this situation.  This does assume that you have correctly
	 * initialised the PCI bus, which you must have done to get
	 * your PC booted.
	 *
	 * Unfortunately, he seems to be blind to this.  I guess he'll
	 * also remove all this.
	 *
	 * And THIS COMMENT STAYS, even if this gets patched, thank
	 * you.
	 */

	/*
	 * Map our SDRAM at a known address in PCI space, just in case
	 * the firmware had other ideas.  Using a nonzero base is
	 * necessary, since some VGA cards forcefully use PCI addresses
	 * in the range 0x000a0000 to 0x000c0000. (eg, S3 cards).
	 *
	 * NOTE! If you need to chec the PCI_CFN bit in the SA110
	 * control register then you've configured the kernel wrong.
	 * If you're not using host mode, then DO NOT set
	 * CONFIG_HOST_FOOTBRIDGE, but use CONFIG_ADDIN_FOOTBRIDGE
	 * instead.  In this case, you MUST supply some firmware
	 * to allow your PC to boot, plus we should not modify the
	 * mappings that the PC BIOS has set up for us.
	 */
	*CSR_PCICACHELINESIZE = 0x00002008;
	*CSR_PCICSRBASE       = 0;
	*CSR_PCICSRIOBASE     = 0;
	*CSR_PCISDRAMBASE     = virt_to_bus((void *)PAGE_OFFSET);
	*CSR_PCIROMBASE       = 0;
	*CSR_PCICMD           = PCI_COMMAND_IO | PCI_COMMAND_MEMORY |
				PCI_COMMAND_MASTER | PCI_COMMAND_FAST_BACK |
				PCI_COMMAND_INVALIDATE | PCI_COMMAND_PARITY |
				(1 << 31) | (1 << 29) | (1 << 28) | (1 << 24);
#endif

	/*
	 * Clear any existing errors - we aren't
	 * interested in historical data...
	 */
	cntl = *CSR_SA110_CNTL & 0xffffde07;
	*CSR_SA110_CNTL = cntl | SA110_CNTL_RXSERR;

	pcibios_init_ebsa285();

	printk(KERN_DEBUG"PCI: DEC21285 revision %02lX\n", *CSR_CLASSREV & 0xff);
}

void __init pcibios_fixup_bus(struct pci_bus *bus)
{
}

char * __init pcibios_setup(char *str)
{
	return str;
}