fdt_common.h revision 247207
1/*-
2 * Copyright (c) 2009-2010 The FreeBSD Foundation
3 * All rights reserved.
4 *
5 * This software was developed by Semihalf under sponsorship from
6 * the FreeBSD Foundation.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * $FreeBSD: head/sys/dev/fdt/fdt_common.h 247207 2013-02-23 22:58:04Z gonzo $
30 */
31
32#ifndef _FDT_COMMON_H_
33#define _FDT_COMMON_H_
34
35#include <sys/slicer.h>
36#include <contrib/libfdt/libfdt_env.h>
37#include <dev/ofw/ofw_bus.h>
38#include <machine/fdt.h>
39
40#define FDT_MEM_REGIONS	8
41
42#define DI_MAX_INTR_NUM	32
43
44struct fdt_pci_range {
45	u_long	base_pci;
46	u_long	base_parent;
47	u_long	len;
48};
49
50struct fdt_pci_intr {
51	int	addr_cells;
52	int	intr_cells;
53	int	map_len;
54	pcell_t	*map;
55	pcell_t	*mask;
56};
57
58struct fdt_sense_level {
59	enum intr_trigger	trig;
60	enum intr_polarity	pol;
61};
62
63typedef int (*fdt_pic_decode_t)(phandle_t, pcell_t *, int *, int *, int *);
64extern fdt_pic_decode_t fdt_pic_table[];
65
66typedef void (*fdt_fixup_t)(phandle_t);
67struct fdt_fixup_entry {
68	char		*model;
69	fdt_fixup_t	handler;
70};
71extern struct fdt_fixup_entry fdt_fixup_table[];
72
73extern vm_paddr_t fdt_immr_pa;
74extern vm_offset_t fdt_immr_va;
75extern vm_offset_t fdt_immr_size;
76
77struct fdt_pm_mask_entry {
78	char		*compat;
79	uint32_t	mask;
80};
81extern struct fdt_pm_mask_entry fdt_pm_mask_table[];
82
83#if defined(FDT_DTB_STATIC)
84extern u_char fdt_static_dtb;
85#endif
86
87int fdt_addrsize_cells(phandle_t, int *, int *);
88u_long fdt_data_get(void *, int);
89int fdt_data_to_res(pcell_t *, int, int, u_long *, u_long *);
90int fdt_data_verify(void *, int);
91phandle_t fdt_find_compatible(phandle_t, const char *, int);
92int fdt_get_mem_regions(struct mem_region *, int *, uint32_t *);
93int fdt_get_reserved_regions(struct mem_region *, int *);
94int fdt_get_phyaddr(phandle_t, device_t, int *, void **);
95int fdt_get_range(phandle_t, int, u_long *, u_long *);
96int fdt_immr_addr(vm_offset_t);
97int fdt_regsize(phandle_t, u_long *, u_long *);
98int fdt_intr_decode(phandle_t, pcell_t *, int *, int *, int *);
99int fdt_intr_to_rl(phandle_t, struct resource_list *, struct fdt_sense_level *);
100int fdt_is_compatible(phandle_t, const char *);
101int fdt_is_compatible_strict(phandle_t, const char *);
102int fdt_is_enabled(phandle_t);
103int fdt_pm_is_enabled(phandle_t);
104int fdt_is_type(phandle_t, const char *);
105int fdt_parent_addr_cells(phandle_t);
106int fdt_pci_intr_info(phandle_t, struct fdt_pci_intr *);
107int fdt_pci_ranges(phandle_t, struct fdt_pci_range *, struct fdt_pci_range *);
108int fdt_pci_ranges_decode(phandle_t, struct fdt_pci_range *,
109    struct fdt_pci_range *);
110int fdt_pci_route_intr(int, int, int, int, struct fdt_pci_intr *, int *);
111int fdt_ranges_verify(pcell_t *, int, int, int, int);
112int fdt_reg_to_rl(phandle_t, struct resource_list *);
113int fdt_pm(phandle_t);
114int fdt_get_unit(device_t);
115
116#endif /* _FDT_COMMON_H_ */
117