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