1*950a6087SEmmanuel Vadot /*- 2*950a6087SEmmanuel Vadot * Copyright 2018 Michal Meloun <mmel@FreeBSD.org> 3*950a6087SEmmanuel Vadot * All rights reserved. 4*950a6087SEmmanuel Vadot * 5*950a6087SEmmanuel Vadot * Redistribution and use in source and binary forms, with or without 6*950a6087SEmmanuel Vadot * modification, are permitted provided that the following conditions 7*950a6087SEmmanuel Vadot * are met: 8*950a6087SEmmanuel Vadot * 1. Redistributions of source code must retain the above copyright 9*950a6087SEmmanuel Vadot * notice, this list of conditions and the following disclaimer. 10*950a6087SEmmanuel Vadot * 2. Redistributions in binary form must reproduce the above copyright 11*950a6087SEmmanuel Vadot * notice, this list of conditions and the following disclaimer in the 12*950a6087SEmmanuel Vadot * documentation and/or other materials provided with the distribution. 13*950a6087SEmmanuel Vadot * 14*950a6087SEmmanuel Vadot * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 15*950a6087SEmmanuel Vadot * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16*950a6087SEmmanuel Vadot * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17*950a6087SEmmanuel Vadot * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 18*950a6087SEmmanuel Vadot * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19*950a6087SEmmanuel Vadot * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20*950a6087SEmmanuel Vadot * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21*950a6087SEmmanuel Vadot * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22*950a6087SEmmanuel Vadot * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23*950a6087SEmmanuel Vadot * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24*950a6087SEmmanuel Vadot */ 25*950a6087SEmmanuel Vadot 26*950a6087SEmmanuel Vadot #ifndef _DEV_PHY_INTERNAL_H_ 27*950a6087SEmmanuel Vadot #define _DEV_PHY_INTERNAL_H_ 28*950a6087SEmmanuel Vadot 29*950a6087SEmmanuel Vadot /* Forward declarations. */ 30*950a6087SEmmanuel Vadot struct phy; 31*950a6087SEmmanuel Vadot struct phynode; 32*950a6087SEmmanuel Vadot 33*950a6087SEmmanuel Vadot typedef TAILQ_HEAD(phynode_list, phynode) phynode_list_t; 34*950a6087SEmmanuel Vadot typedef TAILQ_HEAD(phy_list, phy) phy_list_t; 35*950a6087SEmmanuel Vadot 36*950a6087SEmmanuel Vadot /* 37*950a6087SEmmanuel Vadot * Phy node 38*950a6087SEmmanuel Vadot */ 39*950a6087SEmmanuel Vadot struct phynode { 40*950a6087SEmmanuel Vadot KOBJ_FIELDS; 41*950a6087SEmmanuel Vadot 42*950a6087SEmmanuel Vadot TAILQ_ENTRY(phynode) phylist_link; /* Global list entry */ 43*950a6087SEmmanuel Vadot phy_list_t consumers_list; /* Consumers list */ 44*950a6087SEmmanuel Vadot 45*950a6087SEmmanuel Vadot 46*950a6087SEmmanuel Vadot /* Details of this device. */ 47*950a6087SEmmanuel Vadot const char *name; /* Globally unique name */ 48*950a6087SEmmanuel Vadot 49*950a6087SEmmanuel Vadot device_t pdev; /* Producer device_t */ 50*950a6087SEmmanuel Vadot void *softc; /* Producer softc */ 51*950a6087SEmmanuel Vadot intptr_t id; /* Per producer unique id */ 52*950a6087SEmmanuel Vadot #ifdef FDT 53*950a6087SEmmanuel Vadot phandle_t ofw_node; /* OFW node of phy */ 54*950a6087SEmmanuel Vadot #endif 55*950a6087SEmmanuel Vadot struct sx lock; /* Lock for this phy */ 56*950a6087SEmmanuel Vadot int ref_cnt; /* Reference counter */ 57*950a6087SEmmanuel Vadot int enable_cnt; /* Enabled counter */ 58*950a6087SEmmanuel Vadot }; 59*950a6087SEmmanuel Vadot 60*950a6087SEmmanuel Vadot struct phy { 61*950a6087SEmmanuel Vadot device_t cdev; /* consumer device*/ 62*950a6087SEmmanuel Vadot struct phynode *phynode; 63*950a6087SEmmanuel Vadot TAILQ_ENTRY(phy) link; /* Consumers list entry */ 64*950a6087SEmmanuel Vadot 65*950a6087SEmmanuel Vadot int enable_cnt; 66*950a6087SEmmanuel Vadot }; 67*950a6087SEmmanuel Vadot 68*950a6087SEmmanuel Vadot 69*950a6087SEmmanuel Vadot #define PHY_TOPO_SLOCK() sx_slock(&phynode_topo_lock) 70*950a6087SEmmanuel Vadot #define PHY_TOPO_XLOCK() sx_xlock(&phynode_topo_lock) 71*950a6087SEmmanuel Vadot #define PHY_TOPO_UNLOCK() sx_unlock(&phynode_topo_lock) 72*950a6087SEmmanuel Vadot #define PHY_TOPO_ASSERT() sx_assert(&phynode_topo_lock, SA_LOCKED) 73*950a6087SEmmanuel Vadot #define PHY_TOPO_XASSERT() sx_assert(&phynode_topo_lock, SA_XLOCKED) 74*950a6087SEmmanuel Vadot 75*950a6087SEmmanuel Vadot #define PHYNODE_SLOCK(_sc) sx_slock(&((_sc)->lock)) 76*950a6087SEmmanuel Vadot #define PHYNODE_XLOCK(_sc) sx_xlock(&((_sc)->lock)) 77*950a6087SEmmanuel Vadot #define PHYNODE_UNLOCK(_sc) sx_unlock(&((_sc)->lock)) 78*950a6087SEmmanuel Vadot 79*950a6087SEmmanuel Vadot extern struct sx phynode_topo_lock; 80*950a6087SEmmanuel Vadot 81*950a6087SEmmanuel Vadot #endif /* _DEV_PHY_INTERNAL_H_ */ 82