1*c0da6274SZhi-Jun Robin Fu /* 2*c0da6274SZhi-Jun Robin Fu * CDDL HEADER START 3*c0da6274SZhi-Jun Robin Fu * 4*c0da6274SZhi-Jun Robin Fu * The contents of this file are subject to the terms of the 5*c0da6274SZhi-Jun Robin Fu * Common Development and Distribution License (the "License"). 6*c0da6274SZhi-Jun Robin Fu * You may not use this file except in compliance with the License. 7*c0da6274SZhi-Jun Robin Fu * 8*c0da6274SZhi-Jun Robin Fu * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*c0da6274SZhi-Jun Robin Fu * or http://www.opensolaris.org/os/licensing. 10*c0da6274SZhi-Jun Robin Fu * See the License for the specific language governing permissions 11*c0da6274SZhi-Jun Robin Fu * and limitations under the License. 12*c0da6274SZhi-Jun Robin Fu * 13*c0da6274SZhi-Jun Robin Fu * When distributing Covered Code, include this CDDL HEADER in each 14*c0da6274SZhi-Jun Robin Fu * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*c0da6274SZhi-Jun Robin Fu * If applicable, add the following below this CDDL HEADER, with the 16*c0da6274SZhi-Jun Robin Fu * fields enclosed by brackets "[]" replaced with your own identifying 17*c0da6274SZhi-Jun Robin Fu * information: Portions Copyright [yyyy] [name of copyright owner] 18*c0da6274SZhi-Jun Robin Fu * 19*c0da6274SZhi-Jun Robin Fu * CDDL HEADER END 20*c0da6274SZhi-Jun Robin Fu */ 21*c0da6274SZhi-Jun Robin Fu /* 22*c0da6274SZhi-Jun Robin Fu * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23*c0da6274SZhi-Jun Robin Fu * Use is subject to license terms. 24*c0da6274SZhi-Jun Robin Fu */ 25*c0da6274SZhi-Jun Robin Fu 26*c0da6274SZhi-Jun Robin Fu #ifndef _PCI_CFGACC_H 27*c0da6274SZhi-Jun Robin Fu #define _PCI_CFGACC_H 28*c0da6274SZhi-Jun Robin Fu 29*c0da6274SZhi-Jun Robin Fu #include <sys/dditypes.h> 30*c0da6274SZhi-Jun Robin Fu 31*c0da6274SZhi-Jun Robin Fu #ifdef __cplusplus 32*c0da6274SZhi-Jun Robin Fu extern "C" { 33*c0da6274SZhi-Jun Robin Fu #endif 34*c0da6274SZhi-Jun Robin Fu 35*c0da6274SZhi-Jun Robin Fu #ifndef _ASM 36*c0da6274SZhi-Jun Robin Fu 37*c0da6274SZhi-Jun Robin Fu #define PCI_GETBDF(b, d, f) \ 38*c0da6274SZhi-Jun Robin Fu ((d != 0) ? \ 39*c0da6274SZhi-Jun Robin Fu ((((uint16_t)b & 0xff) << 8) + (((uint8_t)d & 0x1f) << 3) + \ 40*c0da6274SZhi-Jun Robin Fu ((uint8_t)f & 0x7)) : \ 41*c0da6274SZhi-Jun Robin Fu ((((uint16_t)b & 0xff) << 8) + ((uint8_t)f & 0xff))) 42*c0da6274SZhi-Jun Robin Fu 43*c0da6274SZhi-Jun Robin Fu typedef union pci_cfg_data { 44*c0da6274SZhi-Jun Robin Fu uint8_t b; 45*c0da6274SZhi-Jun Robin Fu uint16_t w; 46*c0da6274SZhi-Jun Robin Fu uint32_t dw; 47*c0da6274SZhi-Jun Robin Fu uint64_t qw; 48*c0da6274SZhi-Jun Robin Fu } pci_cfg_data_t; 49*c0da6274SZhi-Jun Robin Fu 50*c0da6274SZhi-Jun Robin Fu typedef enum pci_config_size { 51*c0da6274SZhi-Jun Robin Fu PCI_CFG_SIZE_BYTE = 1, 52*c0da6274SZhi-Jun Robin Fu PCI_CFG_SIZE_WORD = 2, 53*c0da6274SZhi-Jun Robin Fu PCI_CFG_SIZE_DWORD = 4, 54*c0da6274SZhi-Jun Robin Fu PCI_CFG_SIZE_QWORD = 8 55*c0da6274SZhi-Jun Robin Fu } pci_config_size_t; 56*c0da6274SZhi-Jun Robin Fu 57*c0da6274SZhi-Jun Robin Fu typedef struct pci_cfgacc_req { 58*c0da6274SZhi-Jun Robin Fu dev_info_t *rcdip; 59*c0da6274SZhi-Jun Robin Fu uint16_t bdf; 60*c0da6274SZhi-Jun Robin Fu uint16_t offset; 61*c0da6274SZhi-Jun Robin Fu uint8_t size; 62*c0da6274SZhi-Jun Robin Fu boolean_t write; 63*c0da6274SZhi-Jun Robin Fu pci_cfg_data_t value; 64*c0da6274SZhi-Jun Robin Fu boolean_t ioacc; 65*c0da6274SZhi-Jun Robin Fu } pci_cfgacc_req_t; 66*c0da6274SZhi-Jun Robin Fu #define VAL8(req) ((req)->value.b) 67*c0da6274SZhi-Jun Robin Fu #define VAL16(req) ((req)->value.w) 68*c0da6274SZhi-Jun Robin Fu #define VAL32(req) ((req)->value.dw) 69*c0da6274SZhi-Jun Robin Fu #define VAL64(req) ((req)->value.qw) 70*c0da6274SZhi-Jun Robin Fu 71*c0da6274SZhi-Jun Robin Fu extern uint8_t pci_cfgacc_get8(dev_info_t *, uint16_t, uint16_t); 72*c0da6274SZhi-Jun Robin Fu extern uint16_t pci_cfgacc_get16(dev_info_t *, uint16_t, uint16_t); 73*c0da6274SZhi-Jun Robin Fu extern uint32_t pci_cfgacc_get32(dev_info_t *, uint16_t, uint16_t); 74*c0da6274SZhi-Jun Robin Fu extern uint64_t pci_cfgacc_get64(dev_info_t *, uint16_t, uint16_t); 75*c0da6274SZhi-Jun Robin Fu extern void pci_cfgacc_put8(dev_info_t *, uint16_t, uint16_t, uint8_t); 76*c0da6274SZhi-Jun Robin Fu extern void pci_cfgacc_put16(dev_info_t *, uint16_t, uint16_t, uint16_t); 77*c0da6274SZhi-Jun Robin Fu extern void pci_cfgacc_put32(dev_info_t *, uint16_t, uint16_t, uint32_t); 78*c0da6274SZhi-Jun Robin Fu extern void pci_cfgacc_put64(dev_info_t *, uint16_t, uint16_t, uint64_t); 79*c0da6274SZhi-Jun Robin Fu extern void pci_cfgacc_acc(pci_cfgacc_req_t *); 80*c0da6274SZhi-Jun Robin Fu 81*c0da6274SZhi-Jun Robin Fu #endif /* _ASM */ 82*c0da6274SZhi-Jun Robin Fu 83*c0da6274SZhi-Jun Robin Fu #ifdef __cplusplus 84*c0da6274SZhi-Jun Robin Fu } 85*c0da6274SZhi-Jun Robin Fu #endif 86*c0da6274SZhi-Jun Robin Fu 87*c0da6274SZhi-Jun Robin Fu #endif /* _PCI_CFGACC_H */ 88