Linux Audio

Check our new training course

Loading...
v4.17
 
 1/*
 2 * Copyright (C) 2016 Imagination Technologies
 3 * Author: Paul Burton <paul.burton@mips.com>
 4 *
 5 * This program is free software; you can redistribute it and/or modify it
 6 * under the terms of the GNU General Public License as published by the
 7 * Free Software Foundation;  either version 2 of the  License, or (at your
 8 * option) any later version.
 9 */
10
11#ifndef __MIPS_ASM_MACHINE_H__
12#define __MIPS_ASM_MACHINE_H__
13
14#include <linux/libfdt.h>
15#include <linux/of.h>
16
17struct mips_machine {
18	const struct of_device_id *matches;
19	const void *fdt;
20	bool (*detect)(void);
21	const void *(*fixup_fdt)(const void *fdt, const void *match_data);
22	unsigned int (*measure_hpt_freq)(void);
23};
24
25extern long __mips_machines_start;
26extern long __mips_machines_end;
27
28#define MIPS_MACHINE(name)						\
29	static const struct mips_machine __mips_mach_##name		\
30		__used __section(.mips.machines.init)
31
32#define for_each_mips_machine(mach)					\
33	for ((mach) = (struct mips_machine *)&__mips_machines_start;	\
34	     (mach) < (struct mips_machine *)&__mips_machines_end;	\
35	     (mach)++)
36
37/**
38 * mips_machine_is_compatible() - check if a machine is compatible with an FDT
39 * @mach: the machine struct to check
40 * @fdt: the FDT to check for compatibility with
41 *
42 * Check whether the given machine @mach is compatible with the given flattened
43 * device tree @fdt, based upon the compatibility property of the root node.
44 *
45 * Return: the device id matched if any, else NULL
46 */
47static inline const struct of_device_id *
48mips_machine_is_compatible(const struct mips_machine *mach, const void *fdt)
49{
50	const struct of_device_id *match;
51
52	if (!mach->matches)
53		return NULL;
54
55	for (match = mach->matches; match->compatible[0]; match++) {
56		if (fdt_node_check_compatible(fdt, 0, match->compatible) == 0)
57			return match;
58	}
59
60	return NULL;
61}
62
63/**
64 * struct mips_fdt_fixup - Describe a fixup to apply to an FDT
65 * @apply: applies the fixup to @fdt, returns zero on success else -errno
66 * @description: a short description of the fixup
67 *
68 * Describes a fixup applied to an FDT blob by the @apply function. The
69 * @description field provides a short description of the fixup intended for
70 * use in error messages if the @apply function returns non-zero.
71 */
72struct mips_fdt_fixup {
73	int (*apply)(void *fdt);
74	const char *description;
75};
76
77/**
78 * apply_mips_fdt_fixups() - apply fixups to an FDT blob
79 * @fdt_out: buffer in which to place the fixed-up FDT
80 * @fdt_out_size: the size of the @fdt_out buffer
81 * @fdt_in: the FDT blob
82 * @fixups: pointer to an array of fixups to be applied
83 *
84 * Loop through the array of fixups pointed to by @fixups, calling the apply
85 * function on each until either one returns an error or we reach the end of
86 * the list as indicated by an entry with a NULL apply field.
87 *
88 * Return: zero on success, else -errno
89 */
90extern int __init apply_mips_fdt_fixups(void *fdt_out, size_t fdt_out_size,
91					const void *fdt_in,
92					const struct mips_fdt_fixup *fixups);
93
94#endif /* __MIPS_ASM_MACHINE_H__ */
v6.13.7
 1/* SPDX-License-Identifier: GPL-2.0-or-later */
 2/*
 3 * Copyright (C) 2016 Imagination Technologies
 4 * Author: Paul Burton <paul.burton@mips.com>
 
 
 
 
 
 5 */
 6
 7#ifndef __MIPS_ASM_MACHINE_H__
 8#define __MIPS_ASM_MACHINE_H__
 9
10#include <linux/libfdt.h>
11#include <linux/of.h>
12
13struct mips_machine {
14	const struct of_device_id *matches;
15	const void *fdt;
16	bool (*detect)(void);
17	const void *(*fixup_fdt)(const void *fdt, const void *match_data);
18	unsigned int (*measure_hpt_freq)(void);
19};
20
21extern long __mips_machines_start;
22extern long __mips_machines_end;
23
24#define MIPS_MACHINE(name)						\
25	static const struct mips_machine __mips_mach_##name		\
26		__used __section(".mips.machines.init")
27
28#define for_each_mips_machine(mach)					\
29	for ((mach) = (struct mips_machine *)&__mips_machines_start;	\
30	     (mach) < (struct mips_machine *)&__mips_machines_end;	\
31	     (mach)++)
32
33/**
34 * mips_machine_is_compatible() - check if a machine is compatible with an FDT
35 * @mach: the machine struct to check
36 * @fdt: the FDT to check for compatibility with
37 *
38 * Check whether the given machine @mach is compatible with the given flattened
39 * device tree @fdt, based upon the compatibility property of the root node.
40 *
41 * Return: the device id matched if any, else NULL
42 */
43static inline const struct of_device_id *
44mips_machine_is_compatible(const struct mips_machine *mach, const void *fdt)
45{
46	const struct of_device_id *match;
47
48	if (!mach->matches)
49		return NULL;
50
51	for (match = mach->matches; match->compatible[0]; match++) {
52		if (fdt_node_check_compatible(fdt, 0, match->compatible) == 0)
53			return match;
54	}
55
56	return NULL;
57}
58
59/**
60 * struct mips_fdt_fixup - Describe a fixup to apply to an FDT
61 * @apply: applies the fixup to @fdt, returns zero on success else -errno
62 * @description: a short description of the fixup
63 *
64 * Describes a fixup applied to an FDT blob by the @apply function. The
65 * @description field provides a short description of the fixup intended for
66 * use in error messages if the @apply function returns non-zero.
67 */
68struct mips_fdt_fixup {
69	int (*apply)(void *fdt);
70	const char *description;
71};
72
73/**
74 * apply_mips_fdt_fixups() - apply fixups to an FDT blob
75 * @fdt_out: buffer in which to place the fixed-up FDT
76 * @fdt_out_size: the size of the @fdt_out buffer
77 * @fdt_in: the FDT blob
78 * @fixups: pointer to an array of fixups to be applied
79 *
80 * Loop through the array of fixups pointed to by @fixups, calling the apply
81 * function on each until either one returns an error or we reach the end of
82 * the list as indicated by an entry with a NULL apply field.
83 *
84 * Return: zero on success, else -errno
85 */
86extern int __init apply_mips_fdt_fixups(void *fdt_out, size_t fdt_out_size,
87					const void *fdt_in,
88					const struct mips_fdt_fixup *fixups);
89
90#endif /* __MIPS_ASM_MACHINE_H__ */