ops-dreamcast.c 2.6 KB

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