bhnd_pcivar.h revision 296077
1/*- 2 * Copyright (c) 2015 Landon Fuller <landon@landonf.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer, 10 * without modification. 11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 12 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any 13 * redistribution must be conditioned upon including a substantially 14 * similar Disclaimer requirement for further binary redistribution. 15 * 16 * NO WARRANTY 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY 20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, 22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 * THE POSSIBILITY OF SUCH DAMAGES. 28 * 29 * $FreeBSD: head/sys/dev/bhnd/cores/pci/bhnd_pcivar.h 296077 2016-02-26 03:34:08Z adrian $ 30 */ 31 32#ifndef _BHND_CORES_PCI_BHND_PCIVAR_H_ 33#define _BHND_CORES_PCI_BHND_PCIVAR_H_ 34 35#include <sys/param.h> 36#include <sys/bus.h> 37 38/* 39 * Shared PCI Bridge/PCI Host Bridge definitions. 40 */ 41 42extern devclass_t bhnd_mdio_pci_devclass; 43 44/* Device register families. */ 45typedef enum { 46 BHND_PCI_REGFMT_PCI = 0, /* PCI register definitions */ 47 BHND_PCI_REGFMT_PCIE = 1, /* PCIe-Gen1 register definitions */ 48} bhnd_pci_regfmt_t; 49 50/* Common BHND_PCI_*_REG_(EXTRACT|INSERT) implementation */ 51#define _BHND_PCI_REG_EXTRACT(_regval, _mask, _shift) \ 52 ((_regval & _mask) >> _shift) 53#define _BHND_PCI_REG_INSERT(_regval, _mask, _shift, _setval) \ 54 (((_regval) & ~ _mask) | (((_setval) << _shift) & _mask)) 55 56/** 57 * Extract a register value by applying _MASK and _SHIFT defines. 58 * 59 * @param _regv The register value containing the desired attribute 60 * @param _attr The register attribute name to which to append `_MASK`/`_SHIFT` 61 * suffixes. 62 */ 63#define BHND_PCI_REG_EXTRACT(_regv, _attr) \ 64 _BHND_PCI_REG_EXTRACT(_regv, _attr ## _MASK, _attr ## _SHIFT) 65 66/** 67 * Insert a value in @p _regv by applying _MASK and _SHIFT defines. 68 * 69 * @param _regv The current register value. 70 * @param _attr The register attribute name to which to append `_MASK`/`_SHIFT` 71 * suffixes. 72 * @param _val The value to be set in @p _regv. 73 */ 74#define BHND_PCI_REG_INSERT(_regv, _attr, _val) \ 75 _BHND_PCI_REG_INSERT(_regv, _attr ## _MASK, _attr ## _SHIFT, _val) 76 77/** 78 * Extract a value by applying _MASK and _SHIFT defines to the common 79 * PCI/PCIe register definition @p _regv 80 * 81 * @param _regf The PCI core register format (BHNDB_PCI_REGFMT_*). 82 * @param _regv The register value containing the desired attribute 83 * @param _attr The register attribute name to which to prepend the register 84 * definition prefix and append `_MASK`/`_SHIFT` suffixes. 85 */ 86#define BHND_PCI_COMMON_REG_EXTRACT(_regf, _regv, _attr) \ 87 _BHND_PCI_REG_EXTRACT(_regv, \ 88 BHND_PCI_COMMON_REG((_regf), _attr ## _MASK), \ 89 BHND_PCI_COMMON_REG((_regf), _attr ## _SHIFT)) 90 91/** 92 * Insert a register value by applying _MASK and _SHIFT defines to the common 93 * PCI/PCIe register definition @p _regv 94 * 95 * @param _regf The PCI core register format (BHNDB_PCI_REGFMT_*). 96 * @param _regv The register value containing the desired attribute 97 * @param _attr The register attribute name to which to prepend the register 98 * definition prefix and append `_MASK`/`_SHIFT` suffixes. 99 * @param _val The value to bet set in @p _regv. 100 */ 101#define BHND_PCI_COMMON_REG_INSERT(_regf, _regv, _attr, _val) \ 102 _BHND_PCI_REG_INSERT(_regv, \ 103 BHND_PCI_COMMON_REG((_regf), _attr ## _MASK), \ 104 BHND_PCI_COMMON_REG((_regf), _attr ## _SHIFT), \ 105 _val) 106 107 108/** 109 * Evaluates to the offset of a common PCI/PCIe register definition. 110 * 111 * This will trigger a compile-time error if the register is not defined 112 * for all supported PCI/PCIe cores. 113 * 114 * This should be optimized down to a constant value if the register constant 115 * is the same across the register definitions. 116 * 117 * @param _regf The PCI core register format (BHNDB_PCI_REGFMT_*). 118 * @param _name The base name of the register. 119 */ 120#define BHND_PCI_COMMON_REG(_regf, _name) ( \ 121 (_regf) == BHND_PCI_REGFMT_PCI ? BHND_PCI_ ## _name : \ 122 BHND_PCIE_ ## _name \ 123) 124 125#endif /* _BHND_CORES_PCI_BHND_PCIVAR_H_ */