164ae346bSKenneth D. Merry /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3c4e20cadSPedro F. Giffuni * 464ae346bSKenneth D. Merry * Copyright (c) 1997, Stefan Esser <se@FreeBSD.ORG> 564ae346bSKenneth D. Merry * Copyright (c) 1997, 1998, 1999, Kenneth D. Merry <ken@FreeBSD.ORG> 664ae346bSKenneth D. Merry * All rights reserved. 764ae346bSKenneth D. Merry * 864ae346bSKenneth D. Merry * Redistribution and use in source and binary forms, with or without 964ae346bSKenneth D. Merry * modification, are permitted provided that the following conditions 1064ae346bSKenneth D. Merry * are met: 1164ae346bSKenneth D. Merry * 1. Redistributions of source code must retain the above copyright 1264ae346bSKenneth D. Merry * notice unmodified, this list of conditions, and the following 1364ae346bSKenneth D. Merry * disclaimer. 1464ae346bSKenneth D. Merry * 2. Redistributions in binary form must reproduce the above copyright 1564ae346bSKenneth D. Merry * notice, this list of conditions and the following disclaimer in the 1664ae346bSKenneth D. Merry * documentation and/or other materials provided with the distribution. 1764ae346bSKenneth D. Merry * 1864ae346bSKenneth D. Merry * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1964ae346bSKenneth D. Merry * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2064ae346bSKenneth D. Merry * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2164ae346bSKenneth D. Merry * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2264ae346bSKenneth D. Merry * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2364ae346bSKenneth D. Merry * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2464ae346bSKenneth D. Merry * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2564ae346bSKenneth D. Merry * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2664ae346bSKenneth D. Merry * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2764ae346bSKenneth D. Merry * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2864ae346bSKenneth D. Merry * 2964ae346bSKenneth D. Merry */ 3064ae346bSKenneth D. Merry 3164ae346bSKenneth D. Merry #ifndef _SYS_PCIIO_H_ 3264ae346bSKenneth D. Merry #define _SYS_PCIIO_H_ 339ac309b8SStefan Eßer 349ac309b8SStefan Eßer #include <sys/ioccom.h> 359ac309b8SStefan Eßer 3664ae346bSKenneth D. Merry #define PCI_MAXNAMELEN 16 3706915ea6SJustin T. Gibbs 3806915ea6SJustin T. Gibbs typedef enum { 3906915ea6SJustin T. Gibbs PCI_GETCONF_LAST_DEVICE, 4006915ea6SJustin T. Gibbs PCI_GETCONF_LIST_CHANGED, 4106915ea6SJustin T. Gibbs PCI_GETCONF_MORE_DEVS, 4206915ea6SJustin T. Gibbs PCI_GETCONF_ERROR 4306915ea6SJustin T. Gibbs } pci_getconf_status; 4406915ea6SJustin T. Gibbs 4506915ea6SJustin T. Gibbs typedef enum { 4655aaf894SMarius Strobl PCI_GETCONF_NO_MATCH = 0x0000, 4755aaf894SMarius Strobl PCI_GETCONF_MATCH_DOMAIN = 0x0001, 4855aaf894SMarius Strobl PCI_GETCONF_MATCH_BUS = 0x0002, 4955aaf894SMarius Strobl PCI_GETCONF_MATCH_DEV = 0x0004, 5055aaf894SMarius Strobl PCI_GETCONF_MATCH_FUNC = 0x0008, 5155aaf894SMarius Strobl PCI_GETCONF_MATCH_NAME = 0x0010, 5255aaf894SMarius Strobl PCI_GETCONF_MATCH_UNIT = 0x0020, 5355aaf894SMarius Strobl PCI_GETCONF_MATCH_VENDOR = 0x0040, 5455aaf894SMarius Strobl PCI_GETCONF_MATCH_DEVICE = 0x0080, 5555aaf894SMarius Strobl PCI_GETCONF_MATCH_CLASS = 0x0100 5606915ea6SJustin T. Gibbs } pci_getconf_flags; 5706915ea6SJustin T. Gibbs 589ac309b8SStefan Eßer struct pcisel { 5955aaf894SMarius Strobl u_int32_t pc_domain; /* domain number */ 6006915ea6SJustin T. Gibbs u_int8_t pc_bus; /* bus number */ 6106915ea6SJustin T. Gibbs u_int8_t pc_dev; /* device on this bus */ 6206915ea6SJustin T. Gibbs u_int8_t pc_func; /* function on this device */ 639ac309b8SStefan Eßer }; 649ac309b8SStefan Eßer 659ac309b8SStefan Eßer struct pci_conf { 6655aaf894SMarius Strobl struct pcisel pc_sel; /* domain+bus+slot+function */ 6706915ea6SJustin T. Gibbs u_int8_t pc_hdr; /* PCI header type */ 6806915ea6SJustin T. Gibbs u_int16_t pc_subvendor; /* card vendor ID */ 6906915ea6SJustin T. Gibbs u_int16_t pc_subdevice; /* card device ID, assigned by 7006915ea6SJustin T. Gibbs card vendor */ 7106915ea6SJustin T. Gibbs u_int16_t pc_vendor; /* chip vendor ID */ 7206915ea6SJustin T. Gibbs u_int16_t pc_device; /* chip device ID, assigned by 7306915ea6SJustin T. Gibbs chip vendor */ 7406915ea6SJustin T. Gibbs u_int8_t pc_class; /* chip PCI class */ 7506915ea6SJustin T. Gibbs u_int8_t pc_subclass; /* chip PCI subclass */ 7606915ea6SJustin T. Gibbs u_int8_t pc_progif; /* chip PCI programming interface */ 7706915ea6SJustin T. Gibbs u_int8_t pc_revid; /* chip revision ID */ 7864ae346bSKenneth D. Merry char pd_name[PCI_MAXNAMELEN + 1]; /* device name */ 7964ae346bSKenneth D. Merry u_long pd_unit; /* device unit number */ 8006915ea6SJustin T. Gibbs }; 8106915ea6SJustin T. Gibbs 8206915ea6SJustin T. Gibbs struct pci_match_conf { 8355aaf894SMarius Strobl struct pcisel pc_sel; /* domain+bus+slot+function */ 8464ae346bSKenneth D. Merry char pd_name[PCI_MAXNAMELEN + 1]; /* device name */ 8506915ea6SJustin T. Gibbs u_long pd_unit; /* Unit number */ 8606915ea6SJustin T. Gibbs u_int16_t pc_vendor; /* PCI Vendor ID */ 8706915ea6SJustin T. Gibbs u_int16_t pc_device; /* PCI Device ID */ 8806915ea6SJustin T. Gibbs u_int8_t pc_class; /* PCI class */ 8906915ea6SJustin T. Gibbs pci_getconf_flags flags; /* Matching expression */ 909ac309b8SStefan Eßer }; 919ac309b8SStefan Eßer 929ac309b8SStefan Eßer struct pci_conf_io { 9364ae346bSKenneth D. Merry u_int32_t pat_buf_len; /* pattern buffer length */ 9464ae346bSKenneth D. Merry u_int32_t num_patterns; /* number of patterns */ 9564ae346bSKenneth D. Merry struct pci_match_conf *patterns; /* pattern buffer */ 9664ae346bSKenneth D. Merry u_int32_t match_buf_len; /* match buffer length */ 9764ae346bSKenneth D. Merry u_int32_t num_matches; /* number of matches returned */ 9864ae346bSKenneth D. Merry struct pci_conf *matches; /* match buffer */ 9964ae346bSKenneth D. Merry u_int32_t offset; /* offset into device list */ 10064ae346bSKenneth D. Merry u_int32_t generation; /* device list generation */ 10164ae346bSKenneth D. Merry pci_getconf_status status; /* request status */ 1029ac309b8SStefan Eßer }; 1039ac309b8SStefan Eßer 1049ac309b8SStefan Eßer struct pci_io { 1059ac309b8SStefan Eßer struct pcisel pi_sel; /* device to operate on */ 1069ac309b8SStefan Eßer int pi_reg; /* configuration register to examine */ 1079ac309b8SStefan Eßer int pi_width; /* width (in bytes) of read or write */ 1089ac309b8SStefan Eßer u_int32_t pi_data; /* data to write or result of read */ 1099ac309b8SStefan Eßer }; 1109ac309b8SStefan Eßer 111333ebd77SJohn Baldwin struct pci_bar_io { 112333ebd77SJohn Baldwin struct pcisel pbi_sel; /* device to operate on */ 113333ebd77SJohn Baldwin int pbi_reg; /* starting address of BAR */ 114333ebd77SJohn Baldwin int pbi_enabled; /* decoding enabled */ 115333ebd77SJohn Baldwin uint64_t pbi_base; /* current value of BAR */ 116333ebd77SJohn Baldwin uint64_t pbi_length; /* length of BAR */ 117333ebd77SJohn Baldwin }; 118333ebd77SJohn Baldwin 11984b755dfSJohn Baldwin struct pci_vpd_element { 12084b755dfSJohn Baldwin char pve_keyword[2]; 12184b755dfSJohn Baldwin uint8_t pve_flags; 12284b755dfSJohn Baldwin uint8_t pve_datalen; 12384b755dfSJohn Baldwin uint8_t pve_data[0]; 12484b755dfSJohn Baldwin }; 12584b755dfSJohn Baldwin 12684b755dfSJohn Baldwin #define PVE_FLAG_IDENT 0x01 /* Element is the string identifier */ 12784b755dfSJohn Baldwin #define PVE_FLAG_RW 0x02 /* Element is read/write */ 12884b755dfSJohn Baldwin 12984b755dfSJohn Baldwin #define PVE_NEXT(pve) \ 13084b755dfSJohn Baldwin ((struct pci_vpd_element *)((char *)(pve) + \ 13184b755dfSJohn Baldwin sizeof(struct pci_vpd_element) + (pve)->pve_datalen)) 13284b755dfSJohn Baldwin 13384b755dfSJohn Baldwin struct pci_list_vpd_io { 13484b755dfSJohn Baldwin struct pcisel plvi_sel; /* device to operate on */ 13584b755dfSJohn Baldwin size_t plvi_len; /* size of the data area */ 13684b755dfSJohn Baldwin struct pci_vpd_element *plvi_data; 13784b755dfSJohn Baldwin }; 13884b755dfSJohn Baldwin 13987842989SKonstantin Belousov struct pci_bar_mmap { 14087842989SKonstantin Belousov void *pbm_map_base; /* (sometimes IN)/OUT mmaped base */ 14187842989SKonstantin Belousov size_t pbm_map_length; /* mapped length of the BAR, multiple 14287842989SKonstantin Belousov of pages */ 14387842989SKonstantin Belousov uint64_t pbm_bar_length; /* actual length of the BAR */ 14487842989SKonstantin Belousov int pbm_bar_off; /* offset from the mapped base to the 14587842989SKonstantin Belousov start of BAR */ 14687842989SKonstantin Belousov struct pcisel pbm_sel; /* device to operate on */ 14787842989SKonstantin Belousov int pbm_reg; /* starting address of BAR */ 14887842989SKonstantin Belousov int pbm_flags; 14987842989SKonstantin Belousov int pbm_memattr; 15087842989SKonstantin Belousov }; 15187842989SKonstantin Belousov 1527e14be0bSMark Johnston struct pci_bar_ioreq { 1537e14be0bSMark Johnston struct pcisel pbi_sel; /* device to operate on */ 1547e14be0bSMark Johnston #define PCIBARIO_READ 0x1 1557e14be0bSMark Johnston #define PCIBARIO_WRITE 0x2 1567e14be0bSMark Johnston int pbi_op; 1577e14be0bSMark Johnston uint32_t pbi_bar; 1587e14be0bSMark Johnston uint32_t pbi_offset; 1597e14be0bSMark Johnston uint32_t pbi_width; 1607e14be0bSMark Johnston uint32_t pbi_value; 1617e14be0bSMark Johnston }; 1627e14be0bSMark Johnston 16387842989SKonstantin Belousov #define PCIIO_BAR_MMAP_FIXED 0x01 16487842989SKonstantin Belousov #define PCIIO_BAR_MMAP_EXCL 0x02 16587842989SKonstantin Belousov #define PCIIO_BAR_MMAP_RW 0x04 16687842989SKonstantin Belousov #define PCIIO_BAR_MMAP_ACTIVATE 0x08 16787842989SKonstantin Belousov 16833d3fffaSMarius Strobl #define PCIOCGETCONF _IOWR('p', 5, struct pci_conf_io) 1699ac309b8SStefan Eßer #define PCIOCREAD _IOWR('p', 2, struct pci_io) 1709ac309b8SStefan Eßer #define PCIOCWRITE _IOWR('p', 3, struct pci_io) 171993dec9dSStefan Eßer #define PCIOCATTACHED _IOWR('p', 4, struct pci_io) 172333ebd77SJohn Baldwin #define PCIOCGETBAR _IOWR('p', 6, struct pci_bar_io) 17384b755dfSJohn Baldwin #define PCIOCLISTVPD _IOWR('p', 7, struct pci_list_vpd_io) 17487842989SKonstantin Belousov #define PCIOCBARMMAP _IOWR('p', 8, struct pci_bar_mmap) 1757e14be0bSMark Johnston #define PCIOCBARIO _IOWR('p', 9, struct pci_bar_ioreq) 1769ac309b8SStefan Eßer 17764ae346bSKenneth D. Merry #endif /* !_SYS_PCIIO_H_ */ 178