cvmx-coremask.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (c) 2016 Cavium Inc. (support@cavium.com).
  7. *
  8. */
  9. /*
  10. * Module to support operations on bitmap of cores. Coremask can be used to
  11. * select a specific core, a group of cores, or all available cores, for
  12. * initialization and differentiation of roles within a single shared binary
  13. * executable image.
  14. *
  15. * The core numbers used in this file are the same value as what is found in
  16. * the COP0_EBASE register and the rdhwr 0 instruction.
  17. *
  18. * For the CN78XX and other multi-node environments the core numbers are not
  19. * contiguous. The core numbers for the CN78XX are as follows:
  20. *
  21. * Node 0: Cores 0 - 47
  22. * Node 1: Cores 128 - 175
  23. * Node 2: Cores 256 - 303
  24. * Node 3: Cores 384 - 431
  25. *
  26. */
  27. #ifndef __CVMX_COREMASK_H__
  28. #define __CVMX_COREMASK_H__
  29. #define CVMX_MIPS_MAX_CORES 1024
  30. /* bits per holder */
  31. #define CVMX_COREMASK_ELTSZ 64
  32. /* cvmx_coremask_t's size in u64 */
  33. #define CVMX_COREMASK_BMPSZ (CVMX_MIPS_MAX_CORES / CVMX_COREMASK_ELTSZ)
  34. /* cvmx_coremask_t */
  35. struct cvmx_coremask {
  36. u64 coremask_bitmap[CVMX_COREMASK_BMPSZ];
  37. };
  38. /*
  39. * Is ``core'' set in the coremask?
  40. */
  41. static inline bool cvmx_coremask_is_core_set(const struct cvmx_coremask *pcm,
  42. int core)
  43. {
  44. int n, i;
  45. n = core % CVMX_COREMASK_ELTSZ;
  46. i = core / CVMX_COREMASK_ELTSZ;
  47. return (pcm->coremask_bitmap[i] & ((u64)1 << n)) != 0;
  48. }
  49. /*
  50. * Make a copy of a coremask
  51. */
  52. static inline void cvmx_coremask_copy(struct cvmx_coremask *dest,
  53. const struct cvmx_coremask *src)
  54. {
  55. memcpy(dest, src, sizeof(*dest));
  56. }
  57. /*
  58. * Set the lower 64-bit of the coremask.
  59. */
  60. static inline void cvmx_coremask_set64(struct cvmx_coremask *pcm,
  61. uint64_t coremask_64)
  62. {
  63. pcm->coremask_bitmap[0] = coremask_64;
  64. }
  65. /*
  66. * Clear ``core'' from the coremask.
  67. */
  68. static inline void cvmx_coremask_clear_core(struct cvmx_coremask *pcm, int core)
  69. {
  70. int n, i;
  71. n = core % CVMX_COREMASK_ELTSZ;
  72. i = core / CVMX_COREMASK_ELTSZ;
  73. pcm->coremask_bitmap[i] &= ~(1ull << n);
  74. }
  75. #endif /* __CVMX_COREMASK_H__ */