machine.h 2.7 KB

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