1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
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>
15 #define PCI_DEVICE_ID_LOONGSON_HOST 0x7a00
16 #define PCI_DEVICE_ID_LOONGSON_DC1 0x7a06
17 #define PCI_DEVICE_ID_LOONGSON_DC2 0x7a36
19 int raw_pci_read(unsigned int domain
, unsigned int bus
, unsigned int devfn
,
20 int reg
, int len
, u32
*val
)
22 struct pci_bus
*bus_tmp
= pci_find_bus(domain
, bus
);
25 return bus_tmp
->ops
->read(bus_tmp
, devfn
, reg
, len
, val
);
29 int raw_pci_write(unsigned int domain
, unsigned int bus
, unsigned int devfn
,
30 int reg
, int len
, u32 val
)
32 struct pci_bus
*bus_tmp
= pci_find_bus(domain
, bus
);
35 return bus_tmp
->ops
->write(bus_tmp
, devfn
, reg
, len
, val
);
39 phys_addr_t
mcfg_addr_init(int node
)
41 return (((u64
)node
<< 44) | MCFG_EXT_PCICFG_BASE
);
44 static int __init
pcibios_init(void)
49 * Set PCI cacheline size to that of the last level in the
52 lsize
= cpu_last_level_cache_line_size();
56 pci_dfl_cache_line_size
= lsize
>> 2;
58 pr_debug("PCI: pci_cache_line_size set to %d bytes\n", lsize
);
63 subsys_initcall(pcibios_init
);
65 int pcibios_device_add(struct pci_dev
*dev
)
68 struct irq_domain
*dom
;
70 id
= pci_domain_nr(dev
->bus
);
71 dom
= irq_find_matching_fwnode(get_pch_msi_handle(id
), DOMAIN_BUS_PCI_MSI
);
72 dev_set_msi_domain(&dev
->dev
, dom
);
77 int pcibios_alloc_irq(struct pci_dev
*dev
)
81 if (pci_dev_msi_enabled(dev
))
83 return acpi_pci_irq_enable(dev
);
86 static void pci_fixup_vgadev(struct pci_dev
*pdev
)
88 struct pci_dev
*devp
= NULL
;
90 while ((devp
= pci_get_class(PCI_CLASS_DISPLAY_VGA
<< 8, devp
))) {
91 if (devp
->vendor
!= PCI_VENDOR_ID_LOONGSON
) {
92 vga_set_default_device(devp
);
94 "Overriding boot device as %X:%X\n",
95 devp
->vendor
, devp
->device
);
99 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LOONGSON
, PCI_DEVICE_ID_LOONGSON_DC1
, pci_fixup_vgadev
);
100 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LOONGSON
, PCI_DEVICE_ID_LOONGSON_DC2
, pci_fixup_vgadev
);