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 * $FreeBSD$
26 */
27
28#ifndef DEV_EXTRES_PHY_INTERNAL_H
29#define DEV_EXTRES_PHY_INTERNAL_H
30
31/* Forward declarations. */
32struct phy;
33struct phynode;
34
35typedef TAILQ_HEAD(phynode_list, phynode) phynode_list_t;
36typedef TAILQ_HEAD(phy_list, phy) phy_list_t;
37
38/*
39 * Phy node
40 */
41struct phynode {
42	KOBJ_FIELDS;
43
44	TAILQ_ENTRY(phynode)	phylist_link;	/* Global list entry */
45	phy_list_t		consumers_list;	/* Consumers list */
46
47
48	/* Details of this device. */
49	const char		*name;		/* Globally unique name */
50
51	device_t		pdev;		/* Producer device_t */
52	void			*softc;		/* Producer softc */
53	intptr_t		id;		/* Per producer unique id */
54#ifdef FDT
55	 phandle_t		ofw_node;	/* OFW node of phy */
56#endif
57	struct sx		lock;		/* Lock for this phy */
58	int			ref_cnt;	/* Reference counter */
59	int			enable_cnt;	/* Enabled counter */
60};
61
62struct phy {
63	device_t		cdev;		/* consumer device*/
64	struct phynode		*phynode;
65	TAILQ_ENTRY(phy)	link;		/* Consumers list entry */
66
67	int			enable_cnt;
68};
69
70
71#define PHY_TOPO_SLOCK()	sx_slock(&phynode_topo_lock)
72#define PHY_TOPO_XLOCK()	sx_xlock(&phynode_topo_lock)
73#define PHY_TOPO_UNLOCK()	sx_unlock(&phynode_topo_lock)
74#define PHY_TOPO_ASSERT()	sx_assert(&phynode_topo_lock, SA_LOCKED)
75#define PHY_TOPO_XASSERT() 	sx_assert(&phynode_topo_lock, SA_XLOCKED)
76
77#define PHYNODE_SLOCK(_sc)	sx_slock(&((_sc)->lock))
78#define PHYNODE_XLOCK(_sc)	sx_xlock(&((_sc)->lock))
79#define PHYNODE_UNLOCK(_sc)	sx_unlock(&((_sc)->lock))
80
81extern struct sx phynode_topo_lock;
82
83#endif /* DEV_EXTRES_PHY_INTERNAL_H */
84