2 * hades-pci.c - Hardware specific PCI BIOS functions the Hades Atari clone.
4 * Written by Wout Klaren.
7 #include <linux/init.h>
8 #include <linux/kernel.h>
12 # define DBG_DEVS(args) printk args
14 # define DBG_DEVS(args)
17 #if defined(CONFIG_PCI) && defined(CONFIG_HADES)
19 #include <linux/slab.h>
21 #include <linux/pci.h>
23 #include <asm/atarihw.h>
24 #include <asm/atariints.h>
25 #include <asm/byteorder.h>
28 #define HADES_MEM_BASE 0x80000000
29 #define HADES_MEM_SIZE 0x20000000
30 #define HADES_CONFIG_BASE 0xA0000000
31 #define HADES_CONFIG_SIZE 0x10000000
32 #define HADES_IO_BASE 0xB0000000
33 #define HADES_IO_SIZE 0x10000000
34 #define HADES_VIRT_IO_SIZE 0x00010000 /* Only 64k is remapped and actually used. */
36 #define N_SLOTS 4 /* Number of PCI slots. */
38 static const char pci_mem_name
[] = "PCI memory space";
39 static const char pci_io_name
[] = "PCI I/O space";
40 static const char pci_config_name
[] = "PCI config space";
42 static struct resource config_space
= {
43 .name
= pci_config_name
,
44 .start
= HADES_CONFIG_BASE
,
45 .end
= HADES_CONFIG_BASE
+ HADES_CONFIG_SIZE
- 1
47 static struct resource io_space
= {
49 .start
= HADES_IO_BASE
,
50 .end
= HADES_IO_BASE
+ HADES_IO_SIZE
- 1
53 static const unsigned long pci_conf_base_phys
[] = {
54 0xA0080000, 0xA0040000, 0xA0020000, 0xA0010000
56 static unsigned long pci_conf_base_virt
[N_SLOTS
];
57 static unsigned long pci_io_base_virt
;
60 * static void *mk_conf_addr(unsigned char bus, unsigned char device_fn,
61 * unsigned char where)
63 * Calculate the address of the PCI configuration area of the given
66 * BUG: boards with multiple functions are probably not correctly
70 static void *mk_conf_addr(struct pci_dev
*dev
, int where
)
72 int device
= dev
->devfn
>> 3, function
= dev
->devfn
& 7;
75 DBG_DEVS(("mk_conf_addr(bus=%d ,device_fn=0x%x, where=0x%x, pci_addr=0x%p)\n",
76 dev
->bus
->number
, dev
->devfn
, where
, pci_addr
));
80 DBG_DEVS(("mk_conf_addr: device (%d) > 3, returning NULL\n", device
));
84 if (dev
->bus
->number
!= 0)
86 DBG_DEVS(("mk_conf_addr: bus (%d) > 0, returning NULL\n", device
));
90 result
= (void *) (pci_conf_base_virt
[device
] | (function
<< 8) | (where
));
91 DBG_DEVS(("mk_conf_addr: returning pci_addr 0x%lx\n", (unsigned long) result
));
95 static int hades_read_config_byte(struct pci_dev
*dev
, int where
, u8
*value
)
97 volatile unsigned char *pci_addr
;
101 if ((pci_addr
= (unsigned char *) mk_conf_addr(dev
, where
)) == NULL
)
102 return PCIBIOS_DEVICE_NOT_FOUND
;
106 return PCIBIOS_SUCCESSFUL
;
109 static int hades_read_config_word(struct pci_dev
*dev
, int where
, u16
*value
)
111 volatile unsigned short *pci_addr
;
116 return PCIBIOS_BAD_REGISTER_NUMBER
;
118 if ((pci_addr
= (unsigned short *) mk_conf_addr(dev
, where
)) == NULL
)
119 return PCIBIOS_DEVICE_NOT_FOUND
;
121 *value
= le16_to_cpu(*pci_addr
);
123 return PCIBIOS_SUCCESSFUL
;
126 static int hades_read_config_dword(struct pci_dev
*dev
, int where
, u32
*value
)
128 volatile unsigned int *pci_addr
;
129 unsigned char header_type
;
135 return PCIBIOS_BAD_REGISTER_NUMBER
;
137 if ((pci_addr
= (unsigned int *) mk_conf_addr(dev
, where
)) == NULL
)
138 return PCIBIOS_DEVICE_NOT_FOUND
;
140 *value
= le32_to_cpu(*pci_addr
);
143 * Check if the value is an address on the bus. If true, add the
144 * base address of the PCI memory or PCI I/O area on the Hades.
147 if ((result
= hades_read_config_byte(dev
, PCI_HEADER_TYPE
,
148 &header_type
)) != PCIBIOS_SUCCESSFUL
)
151 if (((where
>= PCI_BASE_ADDRESS_0
) && (where
<= PCI_BASE_ADDRESS_1
)) ||
152 ((header_type
!= PCI_HEADER_TYPE_BRIDGE
) && ((where
>= PCI_BASE_ADDRESS_2
) &&
153 (where
<= PCI_BASE_ADDRESS_5
))))
155 if ((*value
& PCI_BASE_ADDRESS_SPACE
) == PCI_BASE_ADDRESS_SPACE_IO
)
158 * Base address register that contains an I/O address. If the
159 * address is valid on the Hades (0 <= *value < HADES_VIRT_IO_SIZE),
160 * add 'pci_io_base_virt' to the value.
163 if (*value
< HADES_VIRT_IO_SIZE
)
164 *value
+= pci_io_base_virt
;
169 * Base address register that contains an memory address. If the
170 * address is valid on the Hades (0 <= *value < HADES_MEM_SIZE),
171 * add HADES_MEM_BASE to the value.
177 * Base address is 0. Test if this base
178 * address register is used.
181 *pci_addr
= 0xffffffff;
185 if (*value
< HADES_MEM_SIZE
)
186 *value
+= HADES_MEM_BASE
;
191 if (*value
< HADES_MEM_SIZE
)
192 *value
+= HADES_MEM_BASE
;
197 return PCIBIOS_SUCCESSFUL
;
200 static int hades_write_config_byte(struct pci_dev
*dev
, int where
, u8 value
)
202 volatile unsigned char *pci_addr
;
204 if ((pci_addr
= (unsigned char *) mk_conf_addr(dev
, where
)) == NULL
)
205 return PCIBIOS_DEVICE_NOT_FOUND
;
209 return PCIBIOS_SUCCESSFUL
;
212 static int hades_write_config_word(struct pci_dev
*dev
, int where
, u16 value
)
214 volatile unsigned short *pci_addr
;
216 if ((pci_addr
= (unsigned short *) mk_conf_addr(dev
, where
)) == NULL
)
217 return PCIBIOS_DEVICE_NOT_FOUND
;
219 *pci_addr
= cpu_to_le16(value
);
221 return PCIBIOS_SUCCESSFUL
;
224 static int hades_write_config_dword(struct pci_dev
*dev
, int where
, u32 value
)
226 volatile unsigned int *pci_addr
;
227 unsigned char header_type
;
230 if ((pci_addr
= (unsigned int *) mk_conf_addr(dev
, where
)) == NULL
)
231 return PCIBIOS_DEVICE_NOT_FOUND
;
234 * Check if the value is an address on the bus. If true, subtract the
235 * base address of the PCI memory or PCI I/O area on the Hades.
238 if ((result
= hades_read_config_byte(dev
, PCI_HEADER_TYPE
,
239 &header_type
)) != PCIBIOS_SUCCESSFUL
)
242 if (((where
>= PCI_BASE_ADDRESS_0
) && (where
<= PCI_BASE_ADDRESS_1
)) ||
243 ((header_type
!= PCI_HEADER_TYPE_BRIDGE
) && ((where
>= PCI_BASE_ADDRESS_2
) &&
244 (where
<= PCI_BASE_ADDRESS_5
))))
246 if ((value
& PCI_BASE_ADDRESS_SPACE
) ==
247 PCI_BASE_ADDRESS_SPACE_IO
)
250 * I/O address. Check if the address is valid address on
251 * the Hades (pci_io_base_virt <= value < pci_io_base_virt +
252 * HADES_VIRT_IO_SIZE) or if the value is 0xffffffff. If not
253 * true do not write the base address register. If it is a
254 * valid base address subtract 'pci_io_base_virt' from the value.
257 if ((value
>= pci_io_base_virt
) && (value
< (pci_io_base_virt
+
258 HADES_VIRT_IO_SIZE
)))
259 value
-= pci_io_base_virt
;
262 if (value
!= 0xffffffff)
263 return PCIBIOS_SET_FAILED
;
269 * Memory address. Check if the address is valid address on
270 * the Hades (HADES_MEM_BASE <= value < HADES_MEM_BASE + HADES_MEM_SIZE) or
271 * if the value is 0xffffffff. If not true do not write
272 * the base address register. If it is a valid base address
273 * subtract HADES_MEM_BASE from the value.
276 if ((value
>= HADES_MEM_BASE
) && (value
< (HADES_MEM_BASE
+ HADES_MEM_SIZE
)))
277 value
-= HADES_MEM_BASE
;
280 if (value
!= 0xffffffff)
281 return PCIBIOS_SET_FAILED
;
286 *pci_addr
= cpu_to_le32(value
);
288 return PCIBIOS_SUCCESSFUL
;
292 * static inline void hades_fixup(void)
294 * Assign IRQ numbers as used by Linux to the interrupt pins
298 static void __init
hades_fixup(int pci_modify
)
301 [0] = IRQ_TT_MFP_IO0
, /* Slot 0. */
302 [1] = IRQ_TT_MFP_IO1
, /* Slot 1. */
303 [2] = IRQ_TT_MFP_SCC
, /* Slot 2. */
304 [3] = IRQ_TT_MFP_SCSIDMA
/* Slot 3. */
306 struct pci_dev
*dev
= NULL
;
310 * Go through all devices, fixing up irqs as we see fit:
313 while ((dev
= pci_get_device(PCI_ANY_ID
, PCI_ANY_ID
, dev
)) != NULL
)
315 if (dev
->class >> 16 != PCI_BASE_CLASS_BRIDGE
)
317 slot
= PCI_SLOT(dev
->devfn
); /* Determine slot number. */
318 dev
->irq
= irq_tab
[slot
];
320 pci_write_config_byte(dev
, PCI_INTERRUPT_LINE
, dev
->irq
);
326 * static void hades_conf_device(struct pci_dev *dev)
328 * Machine dependent Configure the given device.
332 * dev - the pci device.
335 static void __init
hades_conf_device(struct pci_dev
*dev
)
337 pci_write_config_byte(dev
, PCI_CACHE_LINE_SIZE
, 0);
340 static struct pci_ops hades_pci_ops
= {
341 .read_byte
= hades_read_config_byte
,
342 .read_word
= hades_read_config_word
,
343 .read_dword
= hades_read_config_dword
,
344 .write_byte
= hades_write_config_byte
,
345 .write_word
= hades_write_config_word
,
346 .write_dword
= hades_write_config_dword
350 * struct pci_bus_info *init_hades_pci(void)
352 * Machine specific initialisation:
354 * - Allocate and initialise a 'pci_bus_info' structure
355 * - Initialise hardware
357 * Result: pointer to 'pci_bus_info' structure.
360 struct pci_bus_info
* __init
init_hades_pci(void)
362 struct pci_bus_info
*bus
;
366 * Remap I/O and configuration space.
369 pci_io_base_virt
= (unsigned long) ioremap(HADES_IO_BASE
, HADES_VIRT_IO_SIZE
);
371 for (i
= 0; i
< N_SLOTS
; i
++)
372 pci_conf_base_virt
[i
] = (unsigned long) ioremap(pci_conf_base_phys
[i
], 0x10000);
375 * Allocate memory for bus info structure.
378 bus
= kzalloc(sizeof(struct pci_bus_info
), GFP_KERNEL
);
383 * Claim resources. The m68k has no separate I/O space, both
384 * PCI memory space and PCI I/O space are in memory space. Therefore
385 * the I/O resources are requested in memory space as well.
388 if (request_resource(&iomem_resource
, &config_space
) != 0)
394 if (request_resource(&iomem_resource
, &io_space
) != 0)
396 release_resource(&config_space
);
401 bus
->mem_space
.start
= HADES_MEM_BASE
;
402 bus
->mem_space
.end
= HADES_MEM_BASE
+ HADES_MEM_SIZE
- 1;
403 bus
->mem_space
.name
= pci_mem_name
;
405 if (request_resource(&iomem_resource
, &bus
->mem_space
) != 0)
407 release_resource(&io_space
);
408 release_resource(&config_space
);
413 bus
->io_space
.start
= pci_io_base_virt
;
414 bus
->io_space
.end
= pci_io_base_virt
+ HADES_VIRT_IO_SIZE
- 1;
415 bus
->io_space
.name
= pci_io_name
;
417 if (request_resource(&ioport_resource
, &bus
->io_space
) != 0)
419 release_resource(&bus
->mem_space
);
420 release_resource(&io_space
);
421 release_resource(&config_space
);
427 * Set hardware dependent functions.
430 bus
->m68k_pci_ops
= &hades_pci_ops
;
431 bus
->fixup
= hades_fixup
;
432 bus
->conf_device
= hades_conf_device
;
435 * Select high to low edge for PCI interrupts.
438 tt_mfp
.active_edge
&= ~0x27;