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.
10 #define __SYLIXOS_KERNEL
11 #define __SYLIXOS_PCI_DRV
19 sylixos_scan(struct pci_access *a)
24 memset(busmap, 0, sizeof(busmap));
26 for (bus = 0; bus < PCI_MAX_BUS; bus++)
28 pci_generic_scan_bus(a, busmap, bus);
32 sylixos_config(struct pci_access *a)
34 pci_define_param(a, "sylixos.path", PCI_PATH_SYLIXOS_DEVICE, "Path to the SylixOS PCI device");
38 sylixos_detect(struct pci_access *a)
40 char *name = pci_get_param(a, "sylixos.path");
42 if (access(name, R_OK))
44 a->warning("Cannot open %s", name);
48 a->debug("...using %s", name);
53 sylixos_init(struct pci_access *a UNUSED)
58 sylixos_cleanup(struct pci_access *a UNUSED)
63 sylixos_read(struct pci_dev *d, int pos, byte *buf, int len)
70 if (!(len == 1 || len == 2 || len == 4))
71 return pci_generic_block_read(d, pos, buf, len);
79 ret = pciConfigInByte(d->bus, d->dev, d->func, pos, &data_byte);
80 if (ret != ERROR_NONE)
82 buf[0] = (u8)data_byte;
86 ret = pciConfigInWord(d->bus, d->dev, d->func, pos, &data_word);
87 if (ret != ERROR_NONE)
89 ((u16 *) buf)[0] = cpu_to_le16(data_word);
93 ret = pciConfigInDword(d->bus, d->dev, d->func, pos, &data_dword);
94 if (ret != ERROR_NONE)
96 ((u32 *) buf)[0] = cpu_to_le32(data_dword);
104 sylixos_write(struct pci_dev *d, int pos, byte *buf, int len)
111 if (!(len == 1 || len == 2 || len == 4))
112 return pci_generic_block_write(d, pos, buf, len);
121 ret = pciConfigOutByte(d->bus, d->dev, d->func, pos, data_byte);
122 if (ret != ERROR_NONE)
127 data_word = le16_to_cpu(((u16 *) buf)[0]);
128 ret = pciConfigOutWord(d->bus, d->dev, d->func, pos, data_word);
129 if (ret != ERROR_NONE)
134 data_dword = le32_to_cpu(((u32 *) buf)[0]);
135 ret = pciConfigOutDword(d->bus, d->dev, d->func, pos, data_dword);
136 if (ret != ERROR_NONE)
144 struct pci_methods pm_sylixos_device = {
146 "SylixOS /proc/pci device",
152 pci_generic_fill_info,
157 NULL, // no cleanup_dev