[NETLINK]: w1_int.c: fix default netlink group
[linux-2.6/verdex.git] / arch / m68k / atari / hades-pci.c
blob8888debf71ecc739d595f69315fe3ffd3d1e426c
1 /*
2 * hades-pci.c - Hardware specific PCI BIOS functions the Hades Atari clone.
4 * Written by Wout Klaren.
5 */
7 #include <linux/config.h>
8 #include <linux/init.h>
9 #include <linux/kernel.h>
10 #include <asm/io.h>
12 #if 0
13 # define DBG_DEVS(args) printk args
14 #else
15 # define DBG_DEVS(args)
16 #endif
18 #if defined(CONFIG_PCI) && defined(CONFIG_HADES)
20 #include <linux/slab.h>
21 #include <linux/mm.h>
22 #include <linux/pci.h>
24 #include <asm/atarihw.h>
25 #include <asm/atariints.h>
26 #include <asm/byteorder.h>
27 #include <asm/pci.h>
29 #define HADES_MEM_BASE 0x80000000
30 #define HADES_MEM_SIZE 0x20000000
31 #define HADES_CONFIG_BASE 0xA0000000
32 #define HADES_CONFIG_SIZE 0x10000000
33 #define HADES_IO_BASE 0xB0000000
34 #define HADES_IO_SIZE 0x10000000
35 #define HADES_VIRT_IO_SIZE 0x00010000 /* Only 64k is remapped and actually used. */
37 #define N_SLOTS 4 /* Number of PCI slots. */
39 static const char pci_mem_name[] = "PCI memory space";
40 static const char pci_io_name[] = "PCI I/O space";
41 static const char pci_config_name[] = "PCI config space";
43 static struct resource config_space = {
44 .name = pci_config_name,
45 .start = HADES_CONFIG_BASE,
46 .end = HADES_CONFIG_BASE + HADES_CONFIG_SIZE - 1
48 static struct resource io_space = {
49 .name = pci_io_name,
50 .start = HADES_IO_BASE,
51 .end = HADES_IO_BASE + HADES_IO_SIZE - 1
54 static const unsigned long pci_conf_base_phys[] = {
55 0xA0080000, 0xA0040000, 0xA0020000, 0xA0010000
57 static unsigned long pci_conf_base_virt[N_SLOTS];
58 static unsigned long pci_io_base_virt;
61 * static void *mk_conf_addr(unsigned char bus, unsigned char device_fn,
62 * unsigned char where)
64 * Calculate the address of the PCI configuration area of the given
65 * device.
67 * BUG: boards with multiple functions are probably not correctly
68 * supported.
71 static void *mk_conf_addr(struct pci_dev *dev, int where)
73 int device = dev->devfn >> 3, function = dev->devfn & 7;
74 void *result;
76 DBG_DEVS(("mk_conf_addr(bus=%d ,device_fn=0x%x, where=0x%x, pci_addr=0x%p)\n",
77 dev->bus->number, dev->devfn, where, pci_addr));
79 if (device > 3)
81 DBG_DEVS(("mk_conf_addr: device (%d) > 3, returning NULL\n", device));
82 return NULL;
85 if (dev->bus->number != 0)
87 DBG_DEVS(("mk_conf_addr: bus (%d) > 0, returning NULL\n", device));
88 return NULL;
91 result = (void *) (pci_conf_base_virt[device] | (function << 8) | (where));
92 DBG_DEVS(("mk_conf_addr: returning pci_addr 0x%lx\n", (unsigned long) result));
93 return result;
96 static int hades_read_config_byte(struct pci_dev *dev, int where, u8 *value)
98 volatile unsigned char *pci_addr;
100 *value = 0xff;
102 if ((pci_addr = (unsigned char *) mk_conf_addr(dev, where)) == NULL)
103 return PCIBIOS_DEVICE_NOT_FOUND;
105 *value = *pci_addr;
107 return PCIBIOS_SUCCESSFUL;
110 static int hades_read_config_word(struct pci_dev *dev, int where, u16 *value)
112 volatile unsigned short *pci_addr;
114 *value = 0xffff;
116 if (where & 0x1)
117 return PCIBIOS_BAD_REGISTER_NUMBER;
119 if ((pci_addr = (unsigned short *) mk_conf_addr(dev, where)) == NULL)
120 return PCIBIOS_DEVICE_NOT_FOUND;
122 *value = le16_to_cpu(*pci_addr);
124 return PCIBIOS_SUCCESSFUL;
127 static int hades_read_config_dword(struct pci_dev *dev, int where, u32 *value)
129 volatile unsigned int *pci_addr;
130 unsigned char header_type;
131 int result;
133 *value = 0xffffffff;
135 if (where & 0x3)
136 return PCIBIOS_BAD_REGISTER_NUMBER;
138 if ((pci_addr = (unsigned int *) mk_conf_addr(dev, where)) == NULL)
139 return PCIBIOS_DEVICE_NOT_FOUND;
141 *value = le32_to_cpu(*pci_addr);
144 * Check if the value is an address on the bus. If true, add the
145 * base address of the PCI memory or PCI I/O area on the Hades.
148 if ((result = hades_read_config_byte(dev, PCI_HEADER_TYPE,
149 &header_type)) != PCIBIOS_SUCCESSFUL)
150 return result;
152 if (((where >= PCI_BASE_ADDRESS_0) && (where <= PCI_BASE_ADDRESS_1)) ||
153 ((header_type != PCI_HEADER_TYPE_BRIDGE) && ((where >= PCI_BASE_ADDRESS_2) &&
154 (where <= PCI_BASE_ADDRESS_5))))
156 if ((*value & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_IO)
159 * Base address register that contains an I/O address. If the
160 * address is valid on the Hades (0 <= *value < HADES_VIRT_IO_SIZE),
161 * add 'pci_io_base_virt' to the value.
164 if (*value < HADES_VIRT_IO_SIZE)
165 *value += pci_io_base_virt;
167 else
170 * Base address register that contains an memory address. If the
171 * address is valid on the Hades (0 <= *value < HADES_MEM_SIZE),
172 * add HADES_MEM_BASE to the value.
175 if (*value == 0)
178 * Base address is 0. Test if this base
179 * address register is used.
182 *pci_addr = 0xffffffff;
183 if (*pci_addr != 0)
185 *pci_addr = *value;
186 if (*value < HADES_MEM_SIZE)
187 *value += HADES_MEM_BASE;
190 else
192 if (*value < HADES_MEM_SIZE)
193 *value += HADES_MEM_BASE;
198 return PCIBIOS_SUCCESSFUL;
201 static int hades_write_config_byte(struct pci_dev *dev, int where, u8 value)
203 volatile unsigned char *pci_addr;
205 if ((pci_addr = (unsigned char *) mk_conf_addr(dev, where)) == NULL)
206 return PCIBIOS_DEVICE_NOT_FOUND;
208 *pci_addr = value;
210 return PCIBIOS_SUCCESSFUL;
213 static int hades_write_config_word(struct pci_dev *dev, int where, u16 value)
215 volatile unsigned short *pci_addr;
217 if ((pci_addr = (unsigned short *) mk_conf_addr(dev, where)) == NULL)
218 return PCIBIOS_DEVICE_NOT_FOUND;
220 *pci_addr = cpu_to_le16(value);
222 return PCIBIOS_SUCCESSFUL;
225 static int hades_write_config_dword(struct pci_dev *dev, int where, u32 value)
227 volatile unsigned int *pci_addr;
228 unsigned char header_type;
229 int result;
231 if ((pci_addr = (unsigned int *) mk_conf_addr(dev, where)) == NULL)
232 return PCIBIOS_DEVICE_NOT_FOUND;
235 * Check if the value is an address on the bus. If true, subtract the
236 * base address of the PCI memory or PCI I/O area on the Hades.
239 if ((result = hades_read_config_byte(dev, PCI_HEADER_TYPE,
240 &header_type)) != PCIBIOS_SUCCESSFUL)
241 return result;
243 if (((where >= PCI_BASE_ADDRESS_0) && (where <= PCI_BASE_ADDRESS_1)) ||
244 ((header_type != PCI_HEADER_TYPE_BRIDGE) && ((where >= PCI_BASE_ADDRESS_2) &&
245 (where <= PCI_BASE_ADDRESS_5))))
247 if ((value & PCI_BASE_ADDRESS_SPACE) ==
248 PCI_BASE_ADDRESS_SPACE_IO)
251 * I/O address. Check if the address is valid address on
252 * the Hades (pci_io_base_virt <= value < pci_io_base_virt +
253 * HADES_VIRT_IO_SIZE) or if the value is 0xffffffff. If not
254 * true do not write the base address register. If it is a
255 * valid base address subtract 'pci_io_base_virt' from the value.
258 if ((value >= pci_io_base_virt) && (value < (pci_io_base_virt +
259 HADES_VIRT_IO_SIZE)))
260 value -= pci_io_base_virt;
261 else
263 if (value != 0xffffffff)
264 return PCIBIOS_SET_FAILED;
267 else
270 * Memory address. Check if the address is valid address on
271 * the Hades (HADES_MEM_BASE <= value < HADES_MEM_BASE + HADES_MEM_SIZE) or
272 * if the value is 0xffffffff. If not true do not write
273 * the base address register. If it is a valid base address
274 * subtract HADES_MEM_BASE from the value.
277 if ((value >= HADES_MEM_BASE) && (value < (HADES_MEM_BASE + HADES_MEM_SIZE)))
278 value -= HADES_MEM_BASE;
279 else
281 if (value != 0xffffffff)
282 return PCIBIOS_SET_FAILED;
287 *pci_addr = cpu_to_le32(value);
289 return PCIBIOS_SUCCESSFUL;
293 * static inline void hades_fixup(void)
295 * Assign IRQ numbers as used by Linux to the interrupt pins
296 * of the PCI cards.
299 static void __init hades_fixup(int pci_modify)
301 char irq_tab[4] = {
302 [0] = IRQ_TT_MFP_IO0, /* Slot 0. */
303 [1] = IRQ_TT_MFP_IO1, /* Slot 1. */
304 [2] = IRQ_TT_MFP_SCC, /* Slot 2. */
305 [3] = IRQ_TT_MFP_SCSIDMA /* Slot 3. */
307 struct pci_dev *dev = NULL;
308 unsigned char slot;
311 * Go through all devices, fixing up irqs as we see fit:
314 while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL)
316 if (dev->class >> 16 != PCI_BASE_CLASS_BRIDGE)
318 slot = PCI_SLOT(dev->devfn); /* Determine slot number. */
319 dev->irq = irq_tab[slot];
320 if (pci_modify)
321 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
327 * static void hades_conf_device(struct pci_dev *dev)
329 * Machine dependent Configure the given device.
331 * Parameters:
333 * dev - the pci device.
336 static void __init hades_conf_device(struct pci_dev *dev)
338 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, 0);
341 static struct pci_ops hades_pci_ops = {
342 .read_byte = hades_read_config_byte,
343 .read_word = hades_read_config_word,
344 .read_dword = hades_read_config_dword,
345 .write_byte = hades_write_config_byte,
346 .write_word = hades_write_config_word,
347 .write_dword = hades_write_config_dword
351 * struct pci_bus_info *init_hades_pci(void)
353 * Machine specific initialisation:
355 * - Allocate and initialise a 'pci_bus_info' structure
356 * - Initialise hardware
358 * Result: pointer to 'pci_bus_info' structure.
361 struct pci_bus_info * __init init_hades_pci(void)
363 struct pci_bus_info *bus;
364 int i;
367 * Remap I/O and configuration space.
370 pci_io_base_virt = (unsigned long) ioremap(HADES_IO_BASE, HADES_VIRT_IO_SIZE);
372 for (i = 0; i < N_SLOTS; i++)
373 pci_conf_base_virt[i] = (unsigned long) ioremap(pci_conf_base_phys[i], 0x10000);
376 * Allocate memory for bus info structure.
379 bus = kmalloc(sizeof(struct pci_bus_info), GFP_KERNEL);
380 if (!bus)
381 return NULL;
382 memset(bus, 0, sizeof(struct pci_bus_info));
385 * Claim resources. The m68k has no separate I/O space, both
386 * PCI memory space and PCI I/O space are in memory space. Therefore
387 * the I/O resources are requested in memory space as well.
390 if (request_resource(&iomem_resource, &config_space) != 0)
392 kfree(bus);
393 return NULL;
396 if (request_resource(&iomem_resource, &io_space) != 0)
398 release_resource(&config_space);
399 kfree(bus);
400 return NULL;
403 bus->mem_space.start = HADES_MEM_BASE;
404 bus->mem_space.end = HADES_MEM_BASE + HADES_MEM_SIZE - 1;
405 bus->mem_space.name = pci_mem_name;
406 #if 1
407 if (request_resource(&iomem_resource, &bus->mem_space) != 0)
409 release_resource(&io_space);
410 release_resource(&config_space);
411 kfree(bus);
412 return NULL;
414 #endif
415 bus->io_space.start = pci_io_base_virt;
416 bus->io_space.end = pci_io_base_virt + HADES_VIRT_IO_SIZE - 1;
417 bus->io_space.name = pci_io_name;
418 #if 1
419 if (request_resource(&ioport_resource, &bus->io_space) != 0)
421 release_resource(&bus->mem_space);
422 release_resource(&io_space);
423 release_resource(&config_space);
424 kfree(bus);
425 return NULL;
427 #endif
429 * Set hardware dependent functions.
432 bus->m68k_pci_ops = &hades_pci_ops;
433 bus->fixup = hades_fixup;
434 bus->conf_device = hades_conf_device;
437 * Select high to low edge for PCI interrupts.
440 tt_mfp.active_edge &= ~0x27;
442 return bus;
444 #endif