machine.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (C) 2016 Imagination Technologies
  3. * Author: Paul Burton <paul.burton@imgtec.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. #ifndef __MIPS_ASM_MACHINE_H__
  11. #define __MIPS_ASM_MACHINE_H__
  12. #include <linux/libfdt.h>
  13. #include <linux/of.h>
  14. struct mips_machine {
  15. const struct of_device_id *matches;
  16. const void *fdt;
  17. bool (*detect)(void);
  18. const void *(*fixup_fdt)(const void *fdt, const void *match_data);
  19. unsigned int (*measure_hpt_freq)(void);
  20. };
  21. extern long __mips_machines_start;
  22. extern long __mips_machines_end;
  23. #define MIPS_MACHINE(name) \
  24. static const struct mips_machine __mips_mach_##name \
  25. __used __section(.mips.machines.init)
  26. #define for_each_mips_machine(mach) \
  27. for ((mach) = (struct mips_machine *)&__mips_machines_start; \
  28. (mach) < (struct mips_machine *)&__mips_machines_end; \
  29. (mach)++)
  30. /**
  31. * mips_machine_is_compatible() - check if a machine is compatible with an FDT
  32. * @mach: the machine struct to check
  33. * @fdt: the FDT to check for compatibility with
  34. *
  35. * Check whether the given machine @mach is compatible with the given flattened
  36. * device tree @fdt, based upon the compatibility property of the root node.
  37. *
  38. * Return: the device id matched if any, else NULL
  39. */
  40. static inline const struct of_device_id *
  41. mips_machine_is_compatible(const struct mips_machine *mach, const void *fdt)
  42. {
  43. const struct of_device_id *match;
  44. if (!mach->matches)
  45. return NULL;
  46. for (match = mach->matches; match->compatible[0]; match++) {
  47. if (fdt_node_check_compatible(fdt, 0, match->compatible) == 0)
  48. return match;
  49. }
  50. return NULL;
  51. }
  52. #endif /* __MIPS_ASM_MACHINE_H__ */