2 * The PCI Library -- Direct Configuration access via SylixOS Ports
4 * Copyright (c) 2018 YuJian.Gong <gongyujian@acoinfo.com>
6 * Can be freely distributed and used under the terms of the GNU GPL v2+.
8 * SPDX-License-Identifier: GPL-2.0-or-later
12 #define __SYLIXOS_KERNEL
13 #define __SYLIXOS_PCI_DRV
21 sylixos_scan(struct pci_access *a)
26 memset(busmap, 0, sizeof(busmap));
28 for (bus = 0; bus < PCI_MAX_BUS; bus++)
30 pci_generic_scan_bus(a, busmap, 0, bus);
34 sylixos_config(struct pci_access *a)
36 pci_define_param(a, "sylixos.path", PCI_PATH_SYLIXOS_DEVICE, "Path to the SylixOS PCI device");
40 sylixos_detect(struct pci_access *a)
42 char *name = pci_get_param(a, "sylixos.path");
44 if (access(name, R_OK))
46 a->warning("Cannot open %s", name);
50 a->debug("...using %s", name);
55 sylixos_init(struct pci_access *a UNUSED)
60 sylixos_cleanup(struct pci_access *a UNUSED)
65 sylixos_read(struct pci_dev *d, int pos, byte *buf, int len)
72 if (!(len == 1 || len == 2 || len == 4))
73 return pci_generic_block_read(d, pos, buf, len);
81 ret = pciConfigInByte(d->bus, d->dev, d->func, pos, &data_byte);
82 if (ret != ERROR_NONE)
84 buf[0] = (u8)data_byte;
88 ret = pciConfigInWord(d->bus, d->dev, d->func, pos, &data_word);
89 if (ret != ERROR_NONE)
91 ((u16 *) buf)[0] = cpu_to_le16(data_word);
95 ret = pciConfigInDword(d->bus, d->dev, d->func, pos, &data_dword);
96 if (ret != ERROR_NONE)
98 ((u32 *) buf)[0] = cpu_to_le32(data_dword);
106 sylixos_write(struct pci_dev *d, int pos, byte *buf, int len)
113 if (!(len == 1 || len == 2 || len == 4))
114 return pci_generic_block_write(d, pos, buf, len);
123 ret = pciConfigOutByte(d->bus, d->dev, d->func, pos, data_byte);
124 if (ret != ERROR_NONE)
129 data_word = le16_to_cpu(((u16 *) buf)[0]);
130 ret = pciConfigOutWord(d->bus, d->dev, d->func, pos, data_word);
131 if (ret != ERROR_NONE)
136 data_dword = le32_to_cpu(((u32 *) buf)[0]);
137 ret = pciConfigOutDword(d->bus, d->dev, d->func, pos, data_dword);
138 if (ret != ERROR_NONE)
146 struct pci_methods pm_sylixos_device = {
148 "SylixOS /proc/pci device",
154 pci_generic_fill_info,
159 NULL, // no cleanup_dev