xref: /freebsd-13-stable/sys/mips/broadcom/bcm_machdep.h (revision 4b40a16f0d188422227478889b38cc341d50f88f)
1 /*-
2  * Copyright (c) 2016 Landon Fuller <landonf@FreeBSD.org>
3  * Copyright (c) 2017 The FreeBSD Foundation
4  * All rights reserved.
5  *
6  * Portions of this software were developed by Landon Fuller
7  * under sponsorship from the FreeBSD Foundation.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer,
14  *    without modification.
15  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
16  *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
17  *    redistribution must be conditioned upon including a substantially
18  *    similar Disclaimer requirement for further binary redistribution.
19  *
20  * NO WARRANTY
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
24  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
25  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
26  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
29  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31  * THE POSSIBILITY OF SUCH DAMAGES.
32  *
33  */
34 
35 #ifndef	_MIPS_BROADCOM_BCM_MACHDEP_H_
36 #define	_MIPS_BROADCOM_BCM_MACHDEP_H_
37 
38 #include <machine/cpufunc.h>
39 #include <machine/cpuregs.h>
40 
41 #include <dev/bhnd/bhnd.h>
42 #include <dev/bhnd/bhnd_eromvar.h>
43 
44 #include <dev/bhnd/cores/pmu/bhnd_pmuvar.h>
45 
46 #include "bcm_nvram_cfevar.h"
47 
48 extern const struct bhnd_pmu_io	bcm_pmu_soc_io;
49 
50 struct bcm_platform {
51 	struct bhnd_chipid		 cid;		/**< chip id */
52 	struct bhnd_core_info		 cc_id;		/**< chipc core info */
53 	uintptr_t			 cc_addr;	/**< chipc core phys address */
54 	uint32_t			 cc_caps;	/**< chipc capabilities */
55 	uint32_t			 cc_caps_ext;	/**< chipc extended capabilies */
56 
57 	struct bhnd_core_info		 cpu_id;	/**< cpu core info */
58 	uintptr_t			 cpu_addr;	/**< cpu core phys address */
59 
60 	/* On non-AOB devices, the PMU register block is mapped to chipc;
61 	 * the pmu_id and pmu_addr values will be copied from cc_id
62 	 * and cc_addr. */
63 	struct bhnd_core_info		 pmu_id;	/**< PMU core info */
64 	uintptr_t			 pmu_addr;	/**< PMU core phys address, or
65 							     0x0 if no PMU */
66 
67 	struct bhnd_pmu_query		 pmu;		/**< PMU query instance */
68 
69 	bhnd_erom_class_t		*erom_impl;	/**< erom parser class */
70 	struct kobj_ops			 erom_ops;	/**< compiled kobj opcache */
71 	struct bhnd_erom_iobus		 erom_io;	/**< erom I/O callbacks */
72 	union {
73 		bhnd_erom_static_t	 data;
74 		bhnd_erom_t		 obj;
75 	} erom;
76 
77 	struct bhnd_nvram_io		*nvram_io;	/**< NVRAM I/O context, or NULL if unavailable */
78 	bhnd_nvram_data_class		*nvram_cls;	/**< NVRAM data class, or NULL if unavailable */
79 
80 	struct bhnd_service_registry	 services;	/**< platform service providers */
81 
82 #ifdef CFE
83 	int				 cfe_console;	/**< Console handle, or -1 */
84 #endif
85 };
86 
87 struct bcm_platform	*bcm_get_platform(void);
88 
89 uint64_t		 bcm_get_cpufreq(struct bcm_platform *bp);
90 uint64_t		 bcm_get_sifreq(struct bcm_platform *bp);
91 uint64_t		 bcm_get_alpfreq(struct bcm_platform *bp);
92 uint64_t		 bcm_get_ilpfreq(struct bcm_platform *bp);
93 
94 u_int			 bcm_get_uart_rclk(struct bcm_platform *bp);
95 
96 int			 bcm_get_nvram(struct bcm_platform *bp,
97 			     const char *name, void *outp, size_t *olen,
98 			     bhnd_nvram_type type);
99 
100 #define	BCM_ERR(fmt, ...)	\
101 	printf("%s: " fmt, __FUNCTION__, ##__VA_ARGS__)
102 
103 #define	BCM_SOC_BSH(_addr, _offset)			\
104 	((bus_space_handle_t)BCM_SOC_ADDR((_addr), (_offset)))
105 
106 #define	BCM_SOC_ADDR(_addr, _offset)			\
107 	MIPS_PHYS_TO_KSEG1((_addr) + (_offset))
108 
109 #define	BCM_SOC_READ_4(_addr, _offset)			\
110 	readl(BCM_SOC_ADDR((_addr), (_offset)))
111 #define	BCM_SOC_WRITE_4(_addr, _reg, _val)		\
112 	writel(BCM_SOC_ADDR((_addr), (_offset)), (_val))
113 
114 #define	BCM_CORE_ADDR(_bp, _name, _reg)			\
115 	BCM_SOC_ADDR(_bp->_name, (_reg))
116 
117 #define	BCM_CORE_READ_4(_bp, _name, _reg)		\
118 	readl(BCM_CORE_ADDR(_bp, _name, (_reg)))
119 #define	BCM_CORE_WRITE_4(_bp, _name, _reg, _val)	\
120 	writel(BCM_CORE_ADDR(_bp, _name, (_reg)), (_val))
121 
122 #define	BCM_CHIPC_READ_4(_bp, _reg)			\
123 	BCM_CORE_READ_4(_bp, cc_addr, (_reg))
124 #define	BCM_CHIPC_WRITE_4(_bp, _reg, _val)		\
125 	BCM_CORE_WRITE_4(_bp, cc_addr, (_reg), (_val))
126 
127 #define	BCM_CPU_READ_4(_bp, _reg)			\
128 	BCM_CORE_READ_4(_bp, cpu_addr, (_reg))
129 #define	BCM_CPU_WRITE_4(_bp, _reg, _val)		\
130 	BCM_CORE_WRITE_4(_bp, cpu_addr, (_reg), (_val))
131 
132 #define	BCM_PMU_READ_4(_bp, _reg)			\
133 	BCM_CORE_READ_4(_bp, pmu_addr, (_reg))
134 #define	BCM_PMU_WRITE_4(_bp, _reg, _val)		\
135 	BCM_CORE_WRITE_4(_bp, pmu_addr, (_reg), (_val))
136 
137 #endif /* _MIPS_BROADCOM_BCM_MACHDEP_H_ */
138