pci.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/export.h>
  7. #include <linux/init.h>
  8. #include <linux/acpi.h>
  9. #include <linux/types.h>
  10. #include <linux/pci.h>
  11. #include <linux/vgaarb.h>
  12. #include <asm/cacheflush.h>
  13. #include <asm/loongson.h>
  14. #define PCI_DEVICE_ID_LOONGSON_HOST 0x7a00
  15. #define PCI_DEVICE_ID_LOONGSON_DC1 0x7a06
  16. #define PCI_DEVICE_ID_LOONGSON_DC2 0x7a36
  17. int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
  18. int reg, int len, u32 *val)
  19. {
  20. struct pci_bus *bus_tmp = pci_find_bus(domain, bus);
  21. if (bus_tmp)
  22. return bus_tmp->ops->read(bus_tmp, devfn, reg, len, val);
  23. return -EINVAL;
  24. }
  25. int raw_pci_write(unsigned int domain, unsigned int bus, unsigned int devfn,
  26. int reg, int len, u32 val)
  27. {
  28. struct pci_bus *bus_tmp = pci_find_bus(domain, bus);
  29. if (bus_tmp)
  30. return bus_tmp->ops->write(bus_tmp, devfn, reg, len, val);
  31. return -EINVAL;
  32. }
  33. phys_addr_t mcfg_addr_init(int node)
  34. {
  35. return (((u64)node << 44) | MCFG_EXT_PCICFG_BASE);
  36. }
  37. static int __init pcibios_init(void)
  38. {
  39. unsigned int lsize;
  40. /*
  41. * Set PCI cacheline size to that of the last level in the
  42. * cache hierarchy.
  43. */
  44. lsize = cpu_last_level_cache_line_size();
  45. BUG_ON(!lsize);
  46. pci_dfl_cache_line_size = lsize >> 2;
  47. pr_debug("PCI: pci_cache_line_size set to %d bytes\n", lsize);
  48. return 0;
  49. }
  50. subsys_initcall(pcibios_init);
  51. int pcibios_device_add(struct pci_dev *dev)
  52. {
  53. int id;
  54. struct irq_domain *dom;
  55. id = pci_domain_nr(dev->bus);
  56. dom = irq_find_matching_fwnode(get_pch_msi_handle(id), DOMAIN_BUS_PCI_MSI);
  57. dev_set_msi_domain(&dev->dev, dom);
  58. return 0;
  59. }
  60. int pcibios_alloc_irq(struct pci_dev *dev)
  61. {
  62. if (acpi_disabled)
  63. return 0;
  64. if (pci_dev_msi_enabled(dev))
  65. return 0;
  66. return acpi_pci_irq_enable(dev);
  67. }
  68. static void pci_fixup_vgadev(struct pci_dev *pdev)
  69. {
  70. struct pci_dev *devp = NULL;
  71. while ((devp = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, devp))) {
  72. if (devp->vendor != PCI_VENDOR_ID_LOONGSON) {
  73. vga_set_default_device(devp);
  74. dev_info(&pdev->dev,
  75. "Overriding boot device as %X:%X\n",
  76. devp->vendor, devp->device);
  77. }
  78. }
  79. }
  80. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LOONGSON, PCI_DEVICE_ID_LOONGSON_DC1, pci_fixup_vgadev);
  81. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LOONGSON, PCI_DEVICE_ID_LOONGSON_DC2, pci_fixup_vgadev);