3 #include "kvm/ioport.h"
10 #define CMOS_RTC_SECONDS 0x00
11 #define CMOS_RTC_MINUTES 0x02
12 #define CMOS_RTC_HOURS 0x04
13 #define CMOS_RTC_DATE_OF_MONTH 0x07
14 #define CMOS_RTC_MONTH 0x08
15 #define CMOS_RTC_YEAR 0x09
17 static inline unsigned char bin2bcd(unsigned val
)
19 return ((val
/ 10) << 4) + val
% 10;
22 static bool cmos_ram_data_in(struct ioport
*ioport
, struct kvm
*kvm
, u16 port
, void *data
, int size
)
32 case CMOS_RTC_SECONDS
:
33 ioport__write8(data
, bin2bcd(tm
->tm_sec
));
35 case CMOS_RTC_MINUTES
:
36 ioport__write8(data
, bin2bcd(tm
->tm_min
));
39 ioport__write8(data
, bin2bcd(tm
->tm_hour
));
41 case CMOS_RTC_DATE_OF_MONTH
:
42 ioport__write8(data
, bin2bcd(tm
->tm_mday
));
45 ioport__write8(data
, bin2bcd(tm
->tm_mon
+ 1));
48 ioport__write8(data
, bin2bcd(tm
->tm_year
));
55 static bool cmos_ram_data_out(struct ioport
*ioport
, struct kvm
*kvm
, u16 port
, void *data
, int size
)
60 static struct ioport_operations cmos_ram_data_ioport_ops
= {
61 .io_out
= cmos_ram_data_out
,
62 .io_in
= cmos_ram_data_in
,
65 static bool cmos_ram_index_out(struct ioport
*ioport
, struct kvm
*kvm
, u16 port
, void *data
, int size
)
69 value
= ioport__read8(data
);
71 kvm
->nmi_disabled
= value
& (1UL << 7);
73 cmos_index
= value
& ~(1UL << 7);
78 static struct ioport_operations cmos_ram_index_ioport_ops
= {
79 .io_out
= cmos_ram_index_out
,
84 /* PORT 0070-007F - CMOS RAM/RTC (REAL TIME CLOCK) */
85 ioport__register(0x0070, &cmos_ram_index_ioport_ops
, 1, NULL
);
86 ioport__register(0x0071, &cmos_ram_data_ioport_ops
, 1, NULL
);