blob: 3efdbd07752b0fd609bcef4cac64c92deb498abc [file] [log] [blame]
Patrick Georgi55189c92020-05-10 20:09:31 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauer6540ae52007-07-12 16:35:42 +00002
Uwe Hermann6e565942008-03-01 19:06:32 +00003#ifndef NVRAMTOOL_CMOS_LOWLEVEL_H
4#define NVRAMTOOL_CMOS_LOWLEVEL_H
Stefan Reinauer6540ae52007-07-12 16:35:42 +00005
6#include "common.h"
Stefan Reinauera67aab72008-09-27 10:08:28 +00007#include "layout.h"
Stefan Reinauer6540ae52007-07-12 16:35:42 +00008
Patrick Georgi1e916e02011-01-28 07:54:11 +00009typedef 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 Georgi9cd7eba2011-01-21 07:19:59 +000016typedef enum { HAL_CMOS, HAL_MEMORY } hal_t;
17void select_hal(hal_t hal, void *data);
18
Stefan Reinauer6540ae52007-07-12 16:35:42 +000019#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 Reinauer90b96b62010-01-13 21:00:23 +000023unsigned long long cmos_read(const cmos_entry_t * e);
24void cmos_write(const cmos_entry_t * e, unsigned long long value);
25unsigned char cmos_read_byte(unsigned index);
26void cmos_write_byte(unsigned index, unsigned char value);
27void cmos_read_all(unsigned char data[]);
28void cmos_write_all(unsigned char data[]);
29void set_iopl(int level);
30int verify_cmos_op(unsigned bit, unsigned length, cmos_entry_config_t config);
Stefan Reinauer6540ae52007-07-12 16:35:42 +000031
Stefan Reinauer90b96b62010-01-13 21:00:23 +000032#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 Reinauer6540ae52007-07-12 16:35:42 +000034
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 Reinauer90b96b62010-01-13 21:00:23 +000041static inline int verify_cmos_byte_index(unsigned index)
42{
43 return (index < CMOS_RTC_AREA_SIZE) || (index >= CMOS_SIZE);
44}
Stefan Reinauer6540ae52007-07-12 16:35:42 +000045
Stefan Reinauer90b96b62010-01-13 21:00:23 +000046#endif /* NVRAMTOOL_CMOS_LOWLEVEL_H */