154322Sken/*- 254322Sken * Copyright (c) 1997, Stefan Esser <se@FreeBSD.ORG> 354322Sken * Copyright (c) 1997, 1998, 1999, Kenneth D. Merry <ken@FreeBSD.ORG> 454322Sken * All rights reserved. 554322Sken * 654322Sken * Redistribution and use in source and binary forms, with or without 754322Sken * modification, are permitted provided that the following conditions 854322Sken * are met: 954322Sken * 1. Redistributions of source code must retain the above copyright 1054322Sken * notice unmodified, this list of conditions, and the following 1154322Sken * disclaimer. 1254322Sken * 2. Redistributions in binary form must reproduce the above copyright 1354322Sken * notice, this list of conditions and the following disclaimer in the 1454322Sken * documentation and/or other materials provided with the distribution. 1554322Sken * 1654322Sken * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1754322Sken * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1854322Sken * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1954322Sken * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2054322Sken * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2154322Sken * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2254322Sken * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2354322Sken * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2454322Sken * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2554322Sken * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2654322Sken * 2754322Sken * $FreeBSD$ 2854322Sken * 2954322Sken */ 3019104Sse 3154322Sken#ifndef _SYS_PCIIO_H_ 3254322Sken#define _SYS_PCIIO_H_ 3354322Sken 3419104Sse#include <sys/ioccom.h> 3519104Sse 3654322Sken#define PCI_MAXNAMELEN 16 3739231Sgibbs 3839231Sgibbstypedef enum { 3954322Sken PCI_GETCONF_LAST_DEVICE, 4054322Sken PCI_GETCONF_LIST_CHANGED, 4154322Sken PCI_GETCONF_MORE_DEVS, 4254322Sken PCI_GETCONF_ERROR 4339231Sgibbs} pci_getconf_status; 4439231Sgibbs 4539231Sgibbstypedef enum { 46172394Smarius PCI_GETCONF_NO_MATCH = 0x0000, 47172394Smarius PCI_GETCONF_MATCH_DOMAIN = 0x0001, 48172394Smarius PCI_GETCONF_MATCH_BUS = 0x0002, 49172394Smarius PCI_GETCONF_MATCH_DEV = 0x0004, 50172394Smarius PCI_GETCONF_MATCH_FUNC = 0x0008, 51172394Smarius PCI_GETCONF_MATCH_NAME = 0x0010, 52172394Smarius PCI_GETCONF_MATCH_UNIT = 0x0020, 53172394Smarius PCI_GETCONF_MATCH_VENDOR = 0x0040, 54172394Smarius PCI_GETCONF_MATCH_DEVICE = 0x0080, 55172394Smarius PCI_GETCONF_MATCH_CLASS = 0x0100 5639231Sgibbs} pci_getconf_flags; 5739231Sgibbs 5819104Ssestruct pcisel { 59172394Smarius u_int32_t pc_domain; /* domain number */ 6054322Sken u_int8_t pc_bus; /* bus number */ 6154322Sken u_int8_t pc_dev; /* device on this bus */ 6254322Sken u_int8_t pc_func; /* function on this device */ 6319104Sse}; 6419104Sse 6583045Sobrienstruct pci_conf { 66172394Smarius struct pcisel pc_sel; /* domain+bus+slot+function */ 6754322Sken u_int8_t pc_hdr; /* PCI header type */ 6854322Sken u_int16_t pc_subvendor; /* card vendor ID */ 6954322Sken u_int16_t pc_subdevice; /* card device ID, assigned by 7039231Sgibbs card vendor */ 7154322Sken u_int16_t pc_vendor; /* chip vendor ID */ 7254322Sken u_int16_t pc_device; /* chip device ID, assigned by 7339231Sgibbs chip vendor */ 7454322Sken u_int8_t pc_class; /* chip PCI class */ 7554322Sken u_int8_t pc_subclass; /* chip PCI subclass */ 7654322Sken u_int8_t pc_progif; /* chip PCI programming interface */ 7754322Sken u_int8_t pc_revid; /* chip revision ID */ 7854322Sken char pd_name[PCI_MAXNAMELEN + 1]; /* device name */ 7954322Sken u_long pd_unit; /* device unit number */ 8019104Sse}; 8119104Sse 8239231Sgibbsstruct pci_match_conf { 83172394Smarius struct pcisel pc_sel; /* domain+bus+slot+function */ 8454322Sken char pd_name[PCI_MAXNAMELEN + 1]; /* device name */ 8554322Sken u_long pd_unit; /* Unit number */ 8654322Sken u_int16_t pc_vendor; /* PCI Vendor ID */ 8754322Sken u_int16_t pc_device; /* PCI Device ID */ 8854322Sken u_int8_t pc_class; /* PCI class */ 8954322Sken pci_getconf_flags flags; /* Matching expression */ 9039231Sgibbs}; 9139231Sgibbs 9283045Sobrienstruct pci_conf_io { 9354322Sken u_int32_t pat_buf_len; /* pattern buffer length */ 9454322Sken u_int32_t num_patterns; /* number of patterns */ 9554322Sken struct pci_match_conf *patterns; /* pattern buffer */ 9654322Sken u_int32_t match_buf_len; /* match buffer length */ 9754322Sken u_int32_t num_matches; /* number of matches returned */ 9854322Sken struct pci_conf *matches; /* match buffer */ 9954322Sken u_int32_t offset; /* offset into device list */ 10054322Sken u_int32_t generation; /* device list generation */ 10154322Sken pci_getconf_status status; /* request status */ 10219104Sse}; 10319104Sse 10419104Ssestruct pci_io { 10554322Sken struct pcisel pi_sel; /* device to operate on */ 10654322Sken int pi_reg; /* configuration register to examine */ 10754322Sken int pi_width; /* width (in bytes) of read or write */ 10854322Sken u_int32_t pi_data; /* data to write or result of read */ 10919104Sse}; 11019104Sse 111188032Sjhbstruct pci_bar_io { 112188032Sjhb struct pcisel pbi_sel; /* device to operate on */ 113188032Sjhb int pbi_reg; /* starting address of BAR */ 114188032Sjhb int pbi_enabled; /* decoding enabled */ 115188032Sjhb uint64_t pbi_base; /* current value of BAR */ 116188032Sjhb uint64_t pbi_length; /* length of BAR */ 117188032Sjhb}; 118188032Sjhb 119262134Sjhbstruct pci_vpd_element { 120262134Sjhb char pve_keyword[2]; 121262134Sjhb uint8_t pve_flags; 122262134Sjhb uint8_t pve_datalen; 123262134Sjhb uint8_t pve_data[0]; 124262134Sjhb}; 125262134Sjhb 126262134Sjhb#define PVE_FLAG_IDENT 0x01 /* Element is the string identifier */ 127262134Sjhb#define PVE_FLAG_RW 0x02 /* Element is read/write */ 128262134Sjhb 129262134Sjhb#define PVE_NEXT(pve) \ 130262134Sjhb ((struct pci_vpd_element *)((char *)(pve) + \ 131262134Sjhb sizeof(struct pci_vpd_element) + (pve)->pve_datalen)) 132262134Sjhb 133262134Sjhbstruct pci_list_vpd_io { 134262134Sjhb struct pcisel plvi_sel; /* device to operate on */ 135262134Sjhb size_t plvi_len; /* size of the data area */ 136262134Sjhb struct pci_vpd_element *plvi_data; 137262134Sjhb}; 138262134Sjhb 139172932Smarius#define PCIOCGETCONF _IOWR('p', 5, struct pci_conf_io) 14019104Sse#define PCIOCREAD _IOWR('p', 2, struct pci_io) 14119104Sse#define PCIOCWRITE _IOWR('p', 3, struct pci_io) 14221934Sse#define PCIOCATTACHED _IOWR('p', 4, struct pci_io) 143188032Sjhb#define PCIOCGETBAR _IOWR('p', 6, struct pci_bar_io) 144262134Sjhb#define PCIOCLISTVPD _IOWR('p', 7, struct pci_list_vpd_io) 14519104Sse 14654322Sken#endif /* !_SYS_PCIIO_H_ */ 147