fdt_ipi_mswi.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * SPDX-License-Identifier: BSD-2-Clause
  3. *
  4. * Copyright (c) 2021 Western Digital Corporation or its affiliates.
  5. *
  6. * Authors:
  7. * Anup Patel <anup.patel@wdc.com>
  8. */
  9. #include <sbi/sbi_error.h>
  10. #include <sbi_utils/fdt/fdt_helper.h>
  11. #include <sbi_utils/ipi/fdt_ipi.h>
  12. #include <sbi_utils/ipi/aclint_mswi.h>
  13. #define MSWI_MAX_NR 16
  14. static unsigned long mswi_count = 0;
  15. static struct aclint_mswi_data mswi[MSWI_MAX_NR];
  16. static int ipi_mswi_cold_init(void *fdt, int nodeoff,
  17. const struct fdt_match *match)
  18. {
  19. int rc;
  20. unsigned long offset;
  21. struct aclint_mswi_data *ms;
  22. if (MSWI_MAX_NR <= mswi_count)
  23. return SBI_ENOSPC;
  24. ms = &mswi[mswi_count];
  25. rc = fdt_parse_aclint_node(fdt, nodeoff, false,
  26. &ms->addr, &ms->size, NULL, NULL,
  27. &ms->first_hartid, &ms->hart_count);
  28. if (rc)
  29. return rc;
  30. if (match->data) {
  31. /* Adjust MSWI address and size for CLINT device */
  32. offset = *((unsigned long *)match->data);
  33. ms->addr += offset;
  34. if ((ms->size - offset) < ACLINT_MSWI_SIZE)
  35. return SBI_EINVAL;
  36. ms->size = ACLINT_MSWI_SIZE;
  37. }
  38. rc = aclint_mswi_cold_init(ms);
  39. if (rc)
  40. return rc;
  41. mswi_count++;
  42. return 0;
  43. }
  44. static const unsigned long clint_offset = CLINT_MSWI_OFFSET;
  45. static const struct fdt_match ipi_mswi_match[] = {
  46. { .compatible = "riscv,clint0", .data = &clint_offset },
  47. { .compatible = "sifive,clint0", .data = &clint_offset },
  48. { .compatible = "thead,c900-clint", .data = &clint_offset },
  49. { .compatible = "riscv,aclint-mswi" },
  50. { },
  51. };
  52. struct fdt_ipi fdt_ipi_mswi = {
  53. .match_table = ipi_mswi_match,
  54. .cold_init = ipi_mswi_cold_init,
  55. .warm_init = aclint_mswi_warm_init,
  56. .exit = NULL,
  57. };