xref: /freebsd-14.2/sys/dev/extres/syscon/syscon.h (revision 052d3c12)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2017 Kyle Evans <[email protected]>
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  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  * $FreeBSD$
28  */
29 
30 #ifndef DEV_SYSCON_H
31 #define DEV_SYSCON_H
32 
33 #include "opt_platform.h"
34 
35 #include <sys/types.h>
36 #include <sys/kobj.h>
37 #ifdef FDT
38 #include <dev/ofw/ofw_bus.h>
39 #endif
40 
41 struct syscon {
42 	KOBJ_FIELDS;
43 
44 	TAILQ_ENTRY(syscon)	syscon_link;   /* Global list entry */
45 
46 	device_t		pdev;		/* provider device */
47 #ifdef FDT
48 	phandle_t		ofw_node;	/* OFW node for syscon */
49 #endif
50 	void			*softc;		/* provider softc */
51 };
52 
53 /*
54  * Shorthands for constructing method tables.
55  */
56 #define	SYSCONMETHOD		KOBJMETHOD
57 #define	SYSCONMETHOD_END	KOBJMETHOD_END
58 #define	syscon_method_t		kobj_method_t
59 #define	syscon_class_t		kobj_class_t
60 DECLARE_CLASS(syscon_class);
61 
62 void *syscon_get_softc(struct syscon *syscon);
63 
64 /*
65  * Provider interface
66  */
67 struct syscon *syscon_create(device_t pdev, syscon_class_t syscon_class);
68 struct syscon *syscon_register(struct syscon *syscon);
69 int syscon_unregister(struct syscon *syscon);
70 
71 #ifdef FDT
72 struct syscon *syscon_create_ofw_node(device_t pdev,
73     syscon_class_t syscon_class, phandle_t node);
74 phandle_t syscon_get_ofw_node(struct syscon *syscon);
75 int syscon_get_by_ofw_property(device_t consumer, phandle_t node, char *name,
76     struct syscon **syscon);
77 #endif
78 
79 #endif /* DEV_SYSCON_H */
80