blob: 7bffc963a3e3993e3a9a542ed9b3172b65a7d5ac [file] [log] [blame]
Anastasia Klimchuk21e22ba2021-05-10 10:19:25 +10001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright 2021 Google LLC
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16/*
17 * This header is used instead of hwaccess_x86_io.h for unit tests
18 * (see flashrom_test_dep in meson.build).
19 *
20 * There is no hardware in unit test environment and all hardware operations
21 * need to be mocked.
22 */
23
24/*
25 * The same guard is used intentionally for hwaccess_x86_io.h and
26 * hwaccess_x86_io_unittest.h. When build is made for the test environment,
27 * hwaccess_x86_io_unittest.h is included first, and it effectively
28 * replaces hwaccess_x86_io.h.
29 */
30#ifndef __HWACCESS_X86_IO_H__
31#define __HWACCESS_X86_IO_H__ 1
32
33#define OUTB(v, p) test_outb(v, p)
34#define OUTW(v, p) test_outw(v, p)
35#define OUTL(v, p) test_outl(v, p)
36#define INB(p) test_inb(p)
37#define INW(p) test_inw(p)
38#define INL(p) test_inl(p)
39
40#include <stdint.h>
41#include <sys/io.h>
42
43/* All functions below are mocked in unit tests. */
44
45void test_outb(uint8_t value, uint16_t port);
46uint8_t test_inb(uint16_t port);
47void test_outw(uint16_t value, uint16_t port);
48uint16_t test_inw(uint16_t port);
49void test_outl(uint32_t value, uint16_t port);
50uint32_t test_inl(uint16_t port);
51
52#endif /* !__HWACCESS_X86_IO_H__ */