Patrick Georgi | 55189c9 | 2020-05-10 20:09:31 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 2 | |
Uwe Hermann | 6e56594 | 2008-03-01 19:06:32 +0000 | [diff] [blame] | 3 | #ifndef NVRAMTOOL_CMOS_LOWLEVEL_H |
| 4 | #define NVRAMTOOL_CMOS_LOWLEVEL_H |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 5 | |
| 6 | #include "common.h" |
Stefan Reinauer | a67aab7 | 2008-09-27 10:08:28 +0000 | [diff] [blame] | 7 | #include "layout.h" |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 8 | |
Patrick Georgi | 1e916e0 | 2011-01-28 07:54:11 +0000 | [diff] [blame] | 9 | typedef struct { |
| 10 | void (*init)(void* data); |
| 11 | unsigned char (*read)(unsigned addr); |
| 12 | void (*write)(unsigned addr, unsigned char value); |
| 13 | void (*set_iopl)(int level); |
| 14 | } cmos_access_t; |
| 15 | |
Patrick Georgi | 9cd7eba | 2011-01-21 07:19:59 +0000 | [diff] [blame] | 16 | typedef enum { HAL_CMOS, HAL_MEMORY } hal_t; |
| 17 | void select_hal(hal_t hal, void *data); |
| 18 | |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 19 | #define CMOS_AREA_OUT_OF_RANGE (CMOS_RESULT_START + 0) |
| 20 | #define CMOS_AREA_OVERLAPS_RTC (CMOS_RESULT_START + 1) |
| 21 | #define CMOS_AREA_TOO_WIDE (CMOS_RESULT_START + 2) |
| 22 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 23 | unsigned long long cmos_read(const cmos_entry_t * e); |
| 24 | void cmos_write(const cmos_entry_t * e, unsigned long long value); |
| 25 | unsigned char cmos_read_byte(unsigned index); |
| 26 | void cmos_write_byte(unsigned index, unsigned char value); |
| 27 | void cmos_read_all(unsigned char data[]); |
| 28 | void cmos_write_all(unsigned char data[]); |
| 29 | void set_iopl(int level); |
| 30 | int verify_cmos_op(unsigned bit, unsigned length, cmos_entry_config_t config); |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 31 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 32 | #define CMOS_SIZE 256 /* size of CMOS memory in bytes */ |
| 33 | #define CMOS_RTC_AREA_SIZE 14 /* first 14 bytes control real time clock */ |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 34 | |
| 35 | /**************************************************************************** |
| 36 | * verify_cmos_byte_index |
| 37 | * |
| 38 | * Return 1 if 'index' does NOT specify a valid CMOS memory location. Else |
| 39 | * return 0. |
| 40 | ****************************************************************************/ |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 41 | static inline int verify_cmos_byte_index(unsigned index) |
| 42 | { |
| 43 | return (index < CMOS_RTC_AREA_SIZE) || (index >= CMOS_SIZE); |
| 44 | } |
Stefan Reinauer | 6540ae5 | 2007-07-12 16:35:42 +0000 | [diff] [blame] | 45 | |
Stefan Reinauer | 90b96b6 | 2010-01-13 21:00:23 +0000 | [diff] [blame] | 46 | #endif /* NVRAMTOOL_CMOS_LOWLEVEL_H */ |