rpi_mbox_board.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <platform_def.h>
  8. #include <arch_helpers.h>
  9. #include <drivers/rpi3/mailbox/rpi3_mbox.h>
  10. #define RPI3_MBOX_BUFFER_SIZE U(256)
  11. static uint8_t __aligned(16) rpi3_mbox_buffer[RPI3_MBOX_BUFFER_SIZE];
  12. /*******************************************************************************
  13. * Request board revision. Returns the revision and 0 on success, -1 on error.
  14. ******************************************************************************/
  15. int rpi3_vc_hardware_get_board_revision(uint32_t *revision)
  16. {
  17. uint32_t tag_request_size = sizeof(uint32_t);
  18. rpi3_mbox_request_t *req = (rpi3_mbox_request_t *) rpi3_mbox_buffer;
  19. assert(revision != NULL);
  20. VERBOSE("rpi3: mbox: Sending request at %p\n", (void *)req);
  21. req->size = sizeof(rpi3_mbox_buffer);
  22. req->code = RPI3_MBOX_PROCESS_REQUEST;
  23. req->tags[0] = RPI3_TAG_HARDWARE_GET_BOARD_REVISION;
  24. req->tags[1] = tag_request_size; /* Space available for the response */
  25. req->tags[2] = RPI3_TAG_REQUEST;
  26. req->tags[3] = 0; /* Placeholder for the response */
  27. req->tags[4] = RPI3_TAG_END;
  28. rpi3_vc_mailbox_request_send(req, RPI3_MBOX_BUFFER_SIZE);
  29. if (req->code != RPI3_MBOX_REQUEST_SUCCESSFUL) {
  30. ERROR("rpi3: mbox: Code = 0x%08x\n", req->code);
  31. return -1;
  32. }
  33. if (req->tags[2] != (RPI3_TAG_IS_RESPONSE | tag_request_size)) {
  34. ERROR("rpi3: mbox: get board revision failed (0x%08x)\n",
  35. req->tags[2]);
  36. return -1;
  37. }
  38. *revision = req->tags[3];
  39. return 0;
  40. }