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