ops-dreamcast.c 2.4 KB

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