xref: /openbmc/hiomapd/test/bmc_event_ack_v2.c (revision 5335f0930db13a19e1c52b4f746e43db8f79fd76)
14fe996c2SAndrew Jeffery // SPDX-License-Identifier: Apache-2.0
24fe996c2SAndrew Jeffery // Copyright (C) 2018 IBM Corp.
31770ce89SAndrew Jeffery 
41770ce89SAndrew Jeffery #include <assert.h>
51770ce89SAndrew Jeffery #include <sys/mman.h>
61770ce89SAndrew Jeffery #include <sys/types.h>
71770ce89SAndrew Jeffery #include <sys/stat.h>
81770ce89SAndrew Jeffery #include <unistd.h>
91770ce89SAndrew Jeffery 
101770ce89SAndrew Jeffery #include "mbox.h"
11457a6e5fSAndrew Jeffery #include "transport_mbox.h"
121770ce89SAndrew Jeffery 
131770ce89SAndrew Jeffery #include "test/mbox.h"
141770ce89SAndrew Jeffery #include "test/system.h"
151770ce89SAndrew Jeffery 
161770ce89SAndrew Jeffery #define FLAGS 0xc3
171770ce89SAndrew Jeffery 
18b5685b38SAndrew Jeffery static const uint8_t get_info[] = {
19b5685b38SAndrew Jeffery 	0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
20b5685b38SAndrew Jeffery 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
21b5685b38SAndrew Jeffery };
22b5685b38SAndrew Jeffery 
231770ce89SAndrew Jeffery static const uint8_t command[] = {
241770ce89SAndrew Jeffery 	0x09, 0xaa, FLAGS, 0x00, 0x00, 0x00, 0x00, 0x00,
251770ce89SAndrew Jeffery 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, FLAGS
261770ce89SAndrew Jeffery };
271770ce89SAndrew Jeffery 
28b5685b38SAndrew Jeffery uint8_t data[3] = { 0xaa, 0x55, 0xaa };
29b5685b38SAndrew Jeffery 
301770ce89SAndrew Jeffery #define MEM_SIZE	3
311770ce89SAndrew Jeffery #define ERASE_SIZE	1
321770ce89SAndrew Jeffery #define N_WINDOWS	1
331770ce89SAndrew Jeffery #define WINDOW_SIZE	1
341770ce89SAndrew Jeffery 
351770ce89SAndrew Jeffery int main(void)
361770ce89SAndrew Jeffery {
371770ce89SAndrew Jeffery 	struct mbox_context *ctx;
381770ce89SAndrew Jeffery 	struct stat details;
391770ce89SAndrew Jeffery 	uint8_t *map;
401770ce89SAndrew Jeffery 	int rc;
411770ce89SAndrew Jeffery 
421770ce89SAndrew Jeffery 	system_set_reserved_size(MEM_SIZE);
431770ce89SAndrew Jeffery 	system_set_mtd_sizes(MEM_SIZE, ERASE_SIZE);
441770ce89SAndrew Jeffery 
451770ce89SAndrew Jeffery 	ctx = mbox_create_test_context(N_WINDOWS, WINDOW_SIZE);
46b5685b38SAndrew Jeffery 	rc = mbox_set_mtd_data(ctx, data, sizeof(data));
47b5685b38SAndrew Jeffery 	assert(rc == 0);
48b5685b38SAndrew Jeffery 
49b5685b38SAndrew Jeffery 	rc = mbox_command_dispatch(ctx, get_info, sizeof(get_info));
50b5685b38SAndrew Jeffery 	assert(rc == 1);
511770ce89SAndrew Jeffery 
52*5335f093SAndrew Jeffery 	protocol_events_set(ctx, FLAGS, EVENT_TRIGGER);
531770ce89SAndrew Jeffery 
541770ce89SAndrew Jeffery 	rc = mbox_command_dispatch(ctx, command, sizeof(command));
551770ce89SAndrew Jeffery 	assert(rc == 1);
561770ce89SAndrew Jeffery 
571770ce89SAndrew Jeffery 	rc = fstat(ctx->fds[MBOX_FD].fd, &details);
581770ce89SAndrew Jeffery 	assert(rc == 0);
591770ce89SAndrew Jeffery 
601770ce89SAndrew Jeffery 	map = mmap(NULL, details.st_size, PROT_READ, MAP_PRIVATE,
611770ce89SAndrew Jeffery 			ctx->fds[MBOX_FD].fd, 0);
621770ce89SAndrew Jeffery 	assert(map != MAP_FAILED);
631770ce89SAndrew Jeffery 
64b5685b38SAndrew Jeffery 	assert(details.st_size >= 16);
65b5685b38SAndrew Jeffery 	assert(map[15] == 0xc0);
661770ce89SAndrew Jeffery 
67b5685b38SAndrew Jeffery 	return 0;
681770ce89SAndrew Jeffery }
69