1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _SYS_PCI_CAP_H 27 #define _SYS_PCI_CAP_H 28 29 #pragma ident "%Z%%M% %I% %E% SMI" 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 #define PCI_CAP_XCFG_FLAG_SHIFT 31 36 #define PCI_CAP_XCFG_FLAG (1u << PCI_CAP_XCFG_FLAG_SHIFT) 37 38 /* Function Prototypes */ 39 int pci_xcap_locate(ddi_acc_handle_t h, uint16_t id, uint16_t *base_p); 40 int pci_lcap_locate(ddi_acc_handle_t h, uint8_t id, uint16_t *base_p); 41 42 43 /* Extract the lower 16 bits Extended CFG SPACE */ 44 #define PCI_CAP_XID_MASK 0xffff 45 46 /* Extract the lower 8 bits Extended CFG SPACE */ 47 #define PCI_CAP_ID_MASK 0xff 48 49 #define PCI_CAP_XCFG_SPC(i) ((i) ? (i) | PCI_CAP_XCFG_FLAG : 0) 50 51 #ifdef DEBUG 52 #define PCI_CAP_DBG if (pci_cap_debug) printf 53 #else 54 #define PCI_CAP_DBG _NOTE(CONSTANTCONDITION) if (0) printf 55 #endif /* DEBUG */ 56 57 /* 58 * Supported Config Size Reads/Writes 59 */ 60 61 typedef enum { 62 PCI_CAP_CFGSZ_8 = 0, 63 PCI_CAP_CFGSZ_16 = 1, 64 PCI_CAP_CFGSZ_32 = 2 65 } pci_config_size_t; 66 67 /* Define Macros */ 68 69 #define PCI_CAP_LOCATE(h, id, base_p) ((id) & PCI_CAP_XCFG_FLAG ? \ 70 pci_xcap_locate(h, (uint16_t)((id) & PCI_CAP_XID_MASK), base_p) : \ 71 pci_lcap_locate(h, (uint8_t)((id) & PCI_CAP_ID_MASK), base_p)) 72 73 #define PCI_CAP_GET8(h, i, b, o) ((uint8_t) \ 74 pci_cap_get(h, PCI_CAP_CFGSZ_8, i, b, o)) 75 #define PCI_CAP_GET16(h, i, b, o) ((uint16_t) \ 76 pci_cap_get(h, PCI_CAP_CFGSZ_16, i, b, o)) 77 #define PCI_CAP_GET32(h, i, b, o) ((uint32_t) \ 78 pci_cap_get(h, PCI_CAP_CFGSZ_32, i, b, o)) 79 80 #define PCI_CAP_PUT8(h, i, b, o, d) ((uint8_t) \ 81 pci_cap_put(h, PCI_CAP_CFGSZ_8, i, b, o, d)) 82 #define PCI_CAP_PUT16(h, i, b, o, d) ((uint16_t) \ 83 pci_cap_put(h, PCI_CAP_CFGSZ_16, i, b, o, d)) 84 #define PCI_CAP_PUT32(h, i, b, o, d) ((uint32_t) \ 85 pci_cap_put(h, PCI_CAP_CFGSZ_32, i, b, o, d)) 86 87 #define PCI_XCAP_GET8(h, i, b, o) ((uint8_t) \ 88 pci_cap_get(h, PCI_CAP_CFGSZ_8, PCI_CAP_XCFG_SPC(i), b, o)) 89 #define PCI_XCAP_GET16(h, i, b, o) ((uint16_t) \ 90 pci_cap_get(h, PCI_CAP_CFGSZ_16, PCI_CAP_XCFG_SPC(i), b, o)) 91 #define PCI_XCAP_GET32(h, i, b, o) ((uint32_t) \ 92 pci_cap_get(h, PCI_CAP_CFGSZ_32, PCI_CAP_XCFG_SPC(i), b, o)) 93 94 #define PCI_XCAP_PUT8(h, i, b, o, d) ((uint8_t) \ 95 pci_cap_put(h, PCI_CAP_CFGSZ_8, PCI_CAP_XCFG_SPC(i), b, o, d)) 96 #define PCI_XCAP_PUT16(h, i, b, o, d) ((uint16_t) \ 97 pci_cap_put(h, PCI_CAP_CFGSZ_16, PCI_CAP_XCFG_SPC(i), b, o, d)) 98 #define PCI_XCAP_PUT32(h, i, b, o, d) ((uint32_t) \ 99 pci_cap_put(h, PCI_CAP_CFGSZ_32, PCI_CAP_XCFG_SPC(i), b, o, d)) 100 101 102 extern int pci_cap_probe(ddi_acc_handle_t h, uint16_t index, 103 uint32_t *id_p, uint16_t *base_p); 104 105 extern uint32_t pci_cap_get(ddi_acc_handle_t h, pci_config_size_t size, 106 uint32_t id, uint16_t base, uint16_t offset); 107 108 extern int pci_cap_put(ddi_acc_handle_t h, pci_config_size_t size, 109 uint32_t id, uint16_t base, uint16_t offset, uint32_t data); 110 111 extern int pci_cap_read(ddi_acc_handle_t h, uint32_t id, uint16_t base, 112 uint32_t *buf_p, uint32_t nwords); 113 114 extern int pci_cap_count(ddi_acc_handle_t h); 115 116 extern void pci_cap_print(ddi_acc_handle_t h); 117 118 extern void pci_cap_dump(uint32_t *buf_p, uint32_t nwords); 119 120 #ifdef __cplusplus 121 } 122 #endif 123 124 #endif /* _SYS_PCI_CAP_H */ 125