fixup-sb1250.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2004, 2006 MIPS Technologies, Inc. All rights reserved.
  4. * Author: Maciej W. Rozycki <[email protected]>
  5. * Copyright (C) 2018 Maciej W. Rozycki
  6. */
  7. #include <linux/dma-mapping.h>
  8. #include <linux/pci.h>
  9. /*
  10. * Set the BCM1250, etc. PCI host bridge's TRDY timeout
  11. * to the finite max.
  12. */
  13. static void quirk_sb1250_pci(struct pci_dev *dev)
  14. {
  15. pci_write_config_byte(dev, 0x40, 0xff);
  16. }
  17. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SIBYTE, PCI_DEVICE_ID_BCM1250_PCI,
  18. quirk_sb1250_pci);
  19. /*
  20. * The BCM1250, etc. PCI host bridge does not support DAC on its 32-bit
  21. * bus, so we set the bus's DMA limit accordingly. However the HT link
  22. * down the artificial PCI-HT bridge supports 40-bit addressing and the
  23. * SP1011 HT-PCI bridge downstream supports both DAC and a 64-bit bus
  24. * width, so we record the PCI-HT bridge's secondary and subordinate bus
  25. * numbers and do not set the limit for devices present in the inclusive
  26. * range of those.
  27. */
  28. struct sb1250_bus_dma_limit_exclude {
  29. bool set;
  30. unsigned char start;
  31. unsigned char end;
  32. };
  33. static int sb1250_bus_dma_limit(struct pci_dev *dev, void *data)
  34. {
  35. struct sb1250_bus_dma_limit_exclude *exclude = data;
  36. bool exclude_this;
  37. bool ht_bridge;
  38. exclude_this = exclude->set && (dev->bus->number >= exclude->start &&
  39. dev->bus->number <= exclude->end);
  40. ht_bridge = !exclude->set && (dev->vendor == PCI_VENDOR_ID_SIBYTE &&
  41. dev->device == PCI_DEVICE_ID_BCM1250_HT);
  42. if (exclude_this) {
  43. dev_dbg(&dev->dev, "not disabling DAC for device");
  44. } else if (ht_bridge) {
  45. exclude->start = dev->subordinate->number;
  46. exclude->end = pci_bus_max_busnr(dev->subordinate);
  47. exclude->set = true;
  48. dev_dbg(&dev->dev, "not disabling DAC for [bus %02x-%02x]",
  49. exclude->start, exclude->end);
  50. } else {
  51. dev_dbg(&dev->dev, "disabling DAC for device");
  52. dev->dev.bus_dma_limit = DMA_BIT_MASK(32);
  53. }
  54. return 0;
  55. }
  56. static void quirk_sb1250_pci_dac(struct pci_dev *dev)
  57. {
  58. struct sb1250_bus_dma_limit_exclude exclude = { .set = false };
  59. pci_walk_bus(dev->bus, sb1250_bus_dma_limit, &exclude);
  60. }
  61. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SIBYTE, PCI_DEVICE_ID_BCM1250_PCI,
  62. quirk_sb1250_pci_dac);
  63. /*
  64. * The BCM1250, etc. PCI/HT bridge reports as a host bridge.
  65. */
  66. static void quirk_sb1250_ht(struct pci_dev *dev)
  67. {
  68. dev->class = PCI_CLASS_BRIDGE_PCI_NORMAL;
  69. }
  70. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SIBYTE, PCI_DEVICE_ID_BCM1250_HT,
  71. quirk_sb1250_ht);
  72. /*
  73. * Set the SP1011 HT/PCI bridge's TRDY timeout to the finite max.
  74. */
  75. static void quirk_sp1011(struct pci_dev *dev)
  76. {
  77. pci_write_config_byte(dev, 0x64, 0xff);
  78. }
  79. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SIPACKETS, PCI_DEVICE_ID_SP1011,
  80. quirk_sp1011);