1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * PCI operations for the Sega Dreamcast
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (C) 2001, 2002 M. R. Brown
6*4882a593Smuzhiyun * Copyright (C) 2002, 2003 Paul Mundt
7*4882a593Smuzhiyun */
8*4882a593Smuzhiyun
9*4882a593Smuzhiyun #include <linux/sched.h>
10*4882a593Smuzhiyun #include <linux/kernel.h>
11*4882a593Smuzhiyun #include <linux/param.h>
12*4882a593Smuzhiyun #include <linux/interrupt.h>
13*4882a593Smuzhiyun #include <linux/init.h>
14*4882a593Smuzhiyun #include <linux/irq.h>
15*4882a593Smuzhiyun #include <linux/pci.h>
16*4882a593Smuzhiyun #include <linux/module.h>
17*4882a593Smuzhiyun #include <linux/io.h>
18*4882a593Smuzhiyun #include <mach/pci.h>
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun /*
21*4882a593Smuzhiyun * The !gapspci_config_access case really shouldn't happen, ever, unless
22*4882a593Smuzhiyun * someone implicitly messes around with the last devfn value.. otherwise we
23*4882a593Smuzhiyun * only support a single device anyways, and if we didn't have a BBA, we
24*4882a593Smuzhiyun * wouldn't make it terribly far through the PCI setup anyways.
25*4882a593Smuzhiyun *
26*4882a593Smuzhiyun * Also, we could very easily support both Type 0 and Type 1 configurations
27*4882a593Smuzhiyun * here, but since it doesn't seem that there is any such implementation in
28*4882a593Smuzhiyun * existence, we don't bother.
29*4882a593Smuzhiyun *
30*4882a593Smuzhiyun * I suppose if someone actually gets around to ripping the chip out of
31*4882a593Smuzhiyun * the BBA and hanging some more devices off of it, then this might be
32*4882a593Smuzhiyun * something to take into consideration. However, due to the cost of the BBA,
33*4882a593Smuzhiyun * and the general lack of activity by DC hardware hackers, this doesn't seem
34*4882a593Smuzhiyun * likely to happen anytime soon.
35*4882a593Smuzhiyun */
gapspci_config_access(unsigned char bus,unsigned int devfn)36*4882a593Smuzhiyun static int gapspci_config_access(unsigned char bus, unsigned int devfn)
37*4882a593Smuzhiyun {
38*4882a593Smuzhiyun return (bus == 0) && (devfn == 0);
39*4882a593Smuzhiyun }
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun /*
42*4882a593Smuzhiyun * We can also actually read and write in b/w/l sizes! Thankfully this part
43*4882a593Smuzhiyun * was at least done right, and we don't have to do the stupid masking and
44*4882a593Smuzhiyun * shifting that we do on the 7751! Small wonders never cease to amaze.
45*4882a593Smuzhiyun */
gapspci_read(struct pci_bus * bus,unsigned int devfn,int where,int size,u32 * val)46*4882a593Smuzhiyun static int gapspci_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *val)
47*4882a593Smuzhiyun {
48*4882a593Smuzhiyun *val = 0xffffffff;
49*4882a593Smuzhiyun
50*4882a593Smuzhiyun if (!gapspci_config_access(bus->number, devfn))
51*4882a593Smuzhiyun return PCIBIOS_DEVICE_NOT_FOUND;
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun switch (size) {
54*4882a593Smuzhiyun case 1: *val = inb(GAPSPCI_BBA_CONFIG+where); break;
55*4882a593Smuzhiyun case 2: *val = inw(GAPSPCI_BBA_CONFIG+where); break;
56*4882a593Smuzhiyun case 4: *val = inl(GAPSPCI_BBA_CONFIG+where); break;
57*4882a593Smuzhiyun }
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun return PCIBIOS_SUCCESSFUL;
60*4882a593Smuzhiyun }
61*4882a593Smuzhiyun
gapspci_write(struct pci_bus * bus,unsigned int devfn,int where,int size,u32 val)62*4882a593Smuzhiyun static int gapspci_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 val)
63*4882a593Smuzhiyun {
64*4882a593Smuzhiyun if (!gapspci_config_access(bus->number, devfn))
65*4882a593Smuzhiyun return PCIBIOS_DEVICE_NOT_FOUND;
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun switch (size) {
68*4882a593Smuzhiyun case 1: outb(( u8)val, GAPSPCI_BBA_CONFIG+where); break;
69*4882a593Smuzhiyun case 2: outw((u16)val, GAPSPCI_BBA_CONFIG+where); break;
70*4882a593Smuzhiyun case 4: outl((u32)val, GAPSPCI_BBA_CONFIG+where); break;
71*4882a593Smuzhiyun }
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun return PCIBIOS_SUCCESSFUL;
74*4882a593Smuzhiyun }
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun struct pci_ops gapspci_pci_ops = {
77*4882a593Smuzhiyun .read = gapspci_read,
78*4882a593Smuzhiyun .write = gapspci_write,
79*4882a593Smuzhiyun };
80