1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2015 Landon Fuller <landon@landonf.org> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer, 12 * without modification. 13 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 14 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any 15 * redistribution must be conditioned upon including a substantially 16 * similar Disclaimer requirement for further binary redistribution. 17 * 18 * NO WARRANTY 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY 22 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 23 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, 24 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 27 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 29 * THE POSSIBILITY OF SUCH DAMAGES. 30 * 31 */ 32 33 #ifndef _BHND_CORES_PCIE2_BHND_PCIE2_VAR_H_ 34 #define _BHND_CORES_PCIE2_BHND_PCIE2_VAR_H_ 35 36 #include <sys/param.h> 37 #include <sys/bus.h> 38 39 /* 40 * Shared PCIe-G2 Bridge/Host Bridge definitions. 41 */ 42 43 DECLARE_CLASS(bhnd_pcie2_driver); 44 struct bhnd_pcie2_softc; 45 46 int bhnd_pcie2_generic_probe(device_t dev); 47 int bhnd_pcie2_generic_attach(device_t dev); 48 int bhnd_pcie2_generic_detach(device_t dev); 49 int bhnd_pcie2_generic_suspend(device_t dev); 50 int bhnd_pcie2_generic_resume(device_t dev); 51 52 uint32_t bhnd_pcie2_read_proto_reg(struct bhnd_pcie2_softc *sc, 53 uint32_t addr); 54 void bhnd_pcie2_write_proto_reg(struct bhnd_pcie2_softc *sc, 55 uint32_t addr, uint32_t val); 56 int bhnd_pcie2_mdio_read(struct bhnd_pcie2_softc *sc, int phy, 57 int reg); 58 int bhnd_pcie2_mdio_write(struct bhnd_pcie2_softc *sc, int phy, 59 int reg, int val); 60 int bhnd_pcie2_mdio_read_ext(struct bhnd_pcie2_softc *sc, int phy, 61 int devaddr, int reg); 62 int bhnd_pcie2_mdio_write_ext(struct bhnd_pcie2_softc *sc, 63 int phy, int devaddr, int reg, int val); 64 65 /** 66 * bhnd_pcie2 child device info 67 */ 68 struct bhnd_pcie2_devinfo { 69 struct resource_list resources; 70 }; 71 72 /* 73 * Generic PCIe-G2 bridge/end-point driver state. 74 * 75 * Must be first member of all subclass softc structures. 76 */ 77 struct bhnd_pcie2_softc { 78 device_t dev; /**< pci device */ 79 uint32_t quirks; /**< quirk flags */ 80 81 struct mtx mtx; /**< state mutex used to protect 82 interdependent register 83 accesses. */ 84 85 struct bhnd_resource *mem_res; /**< device register block. */ 86 int mem_rid; /**< register block RID */ 87 }; 88 89 #define BHND_PCIE2_LOCK_INIT(sc) \ 90 mtx_init(&(sc)->mtx, device_get_nameunit((sc)->dev), \ 91 "BHND PCIe-G2 driver lock", MTX_DEF) 92 #define BHND_PCIE2_LOCK(sc) mtx_lock(&(sc)->mtx) 93 #define BHND_PCIE2_UNLOCK(sc) mtx_unlock(&(sc)->mtx) 94 #define BHND_PCIE2_LOCK_ASSERT(sc, what) mtx_assert(&(sc)->mtx, what) 95 #define BHND_PCIE2_LOCK_DESTROY(sc) mtx_destroy(&(sc)->mtx) 96 97 #endif /* _BHND_CORES_PCIE2_BHND_PCIE2_VAR_H_ */ 98