Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * Copyright (C) 2016 Imagination Technologies
0004  * Author: Paul Burton <paul.burton@mips.com>
0005  */
0006 
0007 #ifndef __MIPS_ASM_MACHINE_H__
0008 #define __MIPS_ASM_MACHINE_H__
0009 
0010 #include <linux/libfdt.h>
0011 #include <linux/of.h>
0012 
0013 struct mips_machine {
0014     const struct of_device_id *matches;
0015     const void *fdt;
0016     bool (*detect)(void);
0017     const void *(*fixup_fdt)(const void *fdt, const void *match_data);
0018     unsigned int (*measure_hpt_freq)(void);
0019 };
0020 
0021 extern long __mips_machines_start;
0022 extern long __mips_machines_end;
0023 
0024 #define MIPS_MACHINE(name)                      \
0025     static const struct mips_machine __mips_mach_##name     \
0026         __used __section(".mips.machines.init")
0027 
0028 #define for_each_mips_machine(mach)                 \
0029     for ((mach) = (struct mips_machine *)&__mips_machines_start;    \
0030          (mach) < (struct mips_machine *)&__mips_machines_end;  \
0031          (mach)++)
0032 
0033 /**
0034  * mips_machine_is_compatible() - check if a machine is compatible with an FDT
0035  * @mach: the machine struct to check
0036  * @fdt: the FDT to check for compatibility with
0037  *
0038  * Check whether the given machine @mach is compatible with the given flattened
0039  * device tree @fdt, based upon the compatibility property of the root node.
0040  *
0041  * Return: the device id matched if any, else NULL
0042  */
0043 static inline const struct of_device_id *
0044 mips_machine_is_compatible(const struct mips_machine *mach, const void *fdt)
0045 {
0046     const struct of_device_id *match;
0047 
0048     if (!mach->matches)
0049         return NULL;
0050 
0051     for (match = mach->matches; match->compatible[0]; match++) {
0052         if (fdt_node_check_compatible(fdt, 0, match->compatible) == 0)
0053             return match;
0054     }
0055 
0056     return NULL;
0057 }
0058 
0059 /**
0060  * struct mips_fdt_fixup - Describe a fixup to apply to an FDT
0061  * @apply: applies the fixup to @fdt, returns zero on success else -errno
0062  * @description: a short description of the fixup
0063  *
0064  * Describes a fixup applied to an FDT blob by the @apply function. The
0065  * @description field provides a short description of the fixup intended for
0066  * use in error messages if the @apply function returns non-zero.
0067  */
0068 struct mips_fdt_fixup {
0069     int (*apply)(void *fdt);
0070     const char *description;
0071 };
0072 
0073 /**
0074  * apply_mips_fdt_fixups() - apply fixups to an FDT blob
0075  * @fdt_out: buffer in which to place the fixed-up FDT
0076  * @fdt_out_size: the size of the @fdt_out buffer
0077  * @fdt_in: the FDT blob
0078  * @fixups: pointer to an array of fixups to be applied
0079  *
0080  * Loop through the array of fixups pointed to by @fixups, calling the apply
0081  * function on each until either one returns an error or we reach the end of
0082  * the list as indicated by an entry with a NULL apply field.
0083  *
0084  * Return: zero on success, else -errno
0085  */
0086 extern int __init apply_mips_fdt_fixups(void *fdt_out, size_t fdt_out_size,
0087                     const void *fdt_in,
0088                     const struct mips_fdt_fixup *fixups);
0089 
0090 #endif /* __MIPS_ASM_MACHINE_H__ */