xref: /kernel/linux/linux-5.10/arch/loongarch/pci/pci.c (revision 8c2ecf20)
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (C) 2020 Loongson Technology Co., Ltd.
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 <loongson.h>
14
15#define PCI_DEVICE_ID_LOONGSON_HOSTBRIDGE	0x7a00
16
17int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,int reg, int len, u32 *val)
18{
19	struct pci_bus * bus_tmp = pci_find_bus(domain, bus);
20	if (bus_tmp)
21		return bus_tmp->ops->read(bus_tmp, devfn, reg, len, val);
22	return -EINVAL;
23}
24
25int 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
34phys_addr_t mcfg_addr_init(int node)
35{
36	return (((u64)node << 44) | MCFG_EXT_PCICFG_BASE);
37}
38
39static int __init pcibios_init(void)
40{
41	unsigned int lsize;
42
43	/*
44	 * Set PCI cacheline size to that of the last level in the
45	 * cache hierarchy.
46	 */
47	lsize = cpu_last_level_cache_line_size();
48
49	BUG_ON(!lsize);
50
51	pci_dfl_cache_line_size = lsize >> 2;
52
53	pr_debug("PCI: pci_cache_line_size set to %d bytes\n", lsize);
54
55	return 0;
56}
57
58subsys_initcall(pcibios_init);
59
60int pcibios_add_device(struct pci_dev *dev)
61{
62	int id = pci_domain_nr(dev->bus);
63
64	dev_set_msi_domain(&dev->dev, pch_msi_domain[id]);
65
66	return 0;
67}
68
69int pcibios_alloc_irq(struct pci_dev *dev)
70{
71	if (acpi_disabled)
72		return 0;
73	if (pci_dev_msi_enabled(dev))
74		return 0;
75	return acpi_pci_irq_enable(dev);
76}
77
78static void pci_fixup_vgadev(struct pci_dev *pdev)
79{
80	struct pci_dev *devp = NULL;
81
82	while ((devp = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, devp))) {
83		if (devp->vendor != PCI_VENDOR_ID_LOONGSON) {
84			vga_set_default_device(devp);
85			dev_info(&pdev->dev,
86				"Overriding boot device as %X:%X\n",
87				devp->vendor, devp->device);
88		}
89	}
90}
91DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LOONGSON, PCI_DEVICE_ID_LOONGSON_DC1, pci_fixup_vgadev);
92DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LOONGSON, PCI_DEVICE_ID_LOONGSON_DC2, pci_fixup_vgadev);
93