blob: e83d0d3aabe25b66d524f139dda49427a8974c9d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * PCI operations for the Sega Dreamcast
3 *
4 * Copyright (C) 2001, 2002 M. R. Brown
5 * Copyright (C) 2002, 2003 Paul Mundt
6 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
9 * for more details.
10 */
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/sched.h>
13#include <linux/kernel.h>
14#include <linux/param.h>
15#include <linux/interrupt.h>
16#include <linux/init.h>
17#include <linux/irq.h>
18#include <linux/pci.h>
Adrian Bunk7223ce22008-06-18 01:30:40 +030019#include <linux/module.h>
Paul Mundt3444f5e2009-04-20 20:22:05 +090020#include <linux/io.h>
21#include <linux/irq.h>
Paul Mundtf15cbe62008-07-29 08:09:44 +090022#include <mach/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Linus Torvalds1da177e2005-04-16 15:20:36 -070024/*
25 * The !gapspci_config_access case really shouldn't happen, ever, unless
26 * someone implicitly messes around with the last devfn value.. otherwise we
27 * only support a single device anyways, and if we didn't have a BBA, we
28 * wouldn't make it terribly far through the PCI setup anyways.
29 *
30 * Also, we could very easily support both Type 0 and Type 1 configurations
31 * here, but since it doesn't seem that there is any such implementation in
Simon Arlotte868d612007-05-14 08:15:10 +090032 * existence, we don't bother.
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 *
34 * I suppose if someone actually gets around to ripping the chip out of
35 * the BBA and hanging some more devices off of it, then this might be
36 * something to take into consideration. However, due to the cost of the BBA,
37 * and the general lack of activity by DC hardware hackers, this doesn't seem
38 * likely to happen anytime soon.
39 */
40static int gapspci_config_access(unsigned char bus, unsigned int devfn)
41{
42 return (bus == 0) && (devfn == 0);
43}
44
45/*
46 * We can also actually read and write in b/w/l sizes! Thankfully this part
47 * was at least done right, and we don't have to do the stupid masking and
48 * shifting that we do on the 7751! Small wonders never cease to amaze.
49 */
50static int gapspci_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *val)
51{
52 *val = 0xffffffff;
53
54 if (!gapspci_config_access(bus->number, devfn))
55 return PCIBIOS_DEVICE_NOT_FOUND;
56
57 switch (size) {
Paul Mundt3444f5e2009-04-20 20:22:05 +090058 case 1: *val = inb(GAPSPCI_BBA_CONFIG+where); break;
59 case 2: *val = inw(GAPSPCI_BBA_CONFIG+where); break;
60 case 4: *val = inl(GAPSPCI_BBA_CONFIG+where); break;
61 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63 return PCIBIOS_SUCCESSFUL;
64}
65
66static int gapspci_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 val)
67{
68 if (!gapspci_config_access(bus->number, devfn))
69 return PCIBIOS_DEVICE_NOT_FOUND;
70
71 switch (size) {
Paul Mundt3444f5e2009-04-20 20:22:05 +090072 case 1: outb(( u8)val, GAPSPCI_BBA_CONFIG+where); break;
73 case 2: outw((u16)val, GAPSPCI_BBA_CONFIG+where); break;
74 case 4: outl((u32)val, GAPSPCI_BBA_CONFIG+where); break;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 }
76
77 return PCIBIOS_SUCCESSFUL;
78}
79
Paul Mundt3444f5e2009-04-20 20:22:05 +090080struct pci_ops gapspci_pci_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 .read = gapspci_read,
82 .write = gapspci_write,
83};