// SPDX-License-Identifier: GPL-2.01/*2* PCI operations for the Sega Dreamcast3*4* Copyright (C) 2001, 2002 M. R. Brown5* Copyright (C) 2002, 2003 Paul Mundt6*/78#include <linux/sched.h>9#include <linux/kernel.h>10#include <linux/param.h>11#include <linux/interrupt.h>12#include <linux/init.h>13#include <linux/irq.h>14#include <linux/pci.h>15#include <linux/module.h>16#include <linux/io.h>17#include <mach/pci.h>1819/*20* The !gapspci_config_access case really shouldn't happen, ever, unless21* someone implicitly messes around with the last devfn value.. otherwise we22* only support a single device anyways, and if we didn't have a BBA, we23* wouldn't make it terribly far through the PCI setup anyways.24*25* Also, we could very easily support both Type 0 and Type 1 configurations26* here, but since it doesn't seem that there is any such implementation in27* existence, we don't bother.28*29* I suppose if someone actually gets around to ripping the chip out of30* the BBA and hanging some more devices off of it, then this might be31* something to take into consideration. However, due to the cost of the BBA,32* and the general lack of activity by DC hardware hackers, this doesn't seem33* likely to happen anytime soon.34*/35static int gapspci_config_access(unsigned char bus, unsigned int devfn)36{37return (bus == 0) && (devfn == 0);38}3940/*41* We can also actually read and write in b/w/l sizes! Thankfully this part42* was at least done right, and we don't have to do the stupid masking and43* shifting that we do on the 7751! Small wonders never cease to amaze.44*/45static int gapspci_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *val)46{47*val = 0xffffffff;4849if (!gapspci_config_access(bus->number, devfn))50return PCIBIOS_DEVICE_NOT_FOUND;5152switch (size) {53case 1: *val = inb(GAPSPCI_BBA_CONFIG+where); break;54case 2: *val = inw(GAPSPCI_BBA_CONFIG+where); break;55case 4: *val = inl(GAPSPCI_BBA_CONFIG+where); break;56}5758return PCIBIOS_SUCCESSFUL;59}6061static int gapspci_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 val)62{63if (!gapspci_config_access(bus->number, devfn))64return PCIBIOS_DEVICE_NOT_FOUND;6566switch (size) {67case 1: outb(( u8)val, GAPSPCI_BBA_CONFIG+where); break;68case 2: outw((u16)val, GAPSPCI_BBA_CONFIG+where); break;69case 4: outl((u32)val, GAPSPCI_BBA_CONFIG+where); break;70}7172return PCIBIOS_SUCCESSFUL;73}7475struct pci_ops gapspci_pci_ops = {76.read = gapspci_read,77.write = gapspci_write,78};798081