2020-10-13 19:27:48 -03:00
|
|
|
/*
|
|
|
|
|
* 86Box A hypervisor and IBM PC system emulator that specializes in
|
|
|
|
|
* running old operating systems and software designed for IBM
|
|
|
|
|
* PC systems and compatibles from 1981 through fairly recent
|
|
|
|
|
* system designs based on the PCI bus.
|
|
|
|
|
*
|
|
|
|
|
* This file is part of the 86Box distribution.
|
|
|
|
|
*
|
|
|
|
|
* Emulation of the VIA VT82C686A/B integrated hardware monitor.
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* Author: RichardG, <richardg867@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* Copyright 2020 RichardG.
|
|
|
|
|
*/
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#define HAVE_STDARG_H
|
|
|
|
|
#include <wchar.h>
|
|
|
|
|
#include <86box/86box.h>
|
|
|
|
|
#include <86box/device.h>
|
|
|
|
|
#include <86box/io.h>
|
|
|
|
|
#include <86box/hwm.h>
|
|
|
|
|
|
|
|
|
|
|
2020-10-30 20:41:15 -03:00
|
|
|
#define CLAMP(a, min, max) (((a) < (min)) ? (min) : (((a) > (max)) ? (max) : (a)))
|
2020-10-13 19:27:48 -03:00
|
|
|
#define VT82C686_RPM_TO_REG(r, d) ((r) ? CLAMP(1350000 / (r * d), 1, 255) : 0)
|
2020-10-30 20:41:15 -03:00
|
|
|
/* Temperature/voltage formulas and factors derived from Linux's via686a.c driver */
|
2020-10-13 19:27:48 -03:00
|
|
|
#define VT82C686_TEMP_TO_REG(t) (-1.160370e-10*(t*t*t*t*t*t) + 3.193693e-08*(t*t*t*t*t) - 1.464447e-06*(t*t*t*t) - 2.525453e-04*(t*t*t) + 1.424593e-02*(t*t) + 2.148941e+00*t + 7.275808e+01)
|
2020-10-30 20:41:15 -03:00
|
|
|
#define VT82C686_VOLTAGE_TO_REG(v, f) CLAMP((((v) * (2.628 / (f))) - 120.5) / 25, 0, 255)
|
2020-10-13 19:27:48 -03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
hwm_values_t *values;
|
|
|
|
|
device_t *lm75[2];
|
|
|
|
|
|
|
|
|
|
uint8_t enable;
|
|
|
|
|
uint16_t io_base;
|
|
|
|
|
uint8_t regs[80];
|
|
|
|
|
} vt82c686_t;
|
|
|
|
|
|
|
|
|
|
|
2020-11-10 22:02:30 -03:00
|
|
|
static double voltage_factors[5] = {1.25, 1.25, 1.67, 2.6, 6.3};
|
|
|
|
|
|
|
|
|
|
|
2020-10-13 19:27:48 -03:00
|
|
|
static void vt82c686_reset(vt82c686_t *dev, uint8_t initialization);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static uint8_t
|
|
|
|
|
vt82c686_read(uint16_t addr, void *priv)
|
|
|
|
|
{
|
|
|
|
|
vt82c686_t *dev = (vt82c686_t *) priv;
|
2020-11-11 14:45:07 -03:00
|
|
|
uint8_t ret;
|
2020-11-10 22:02:30 -03:00
|
|
|
|
|
|
|
|
addr -= dev->io_base;
|
|
|
|
|
|
|
|
|
|
switch (addr) {
|
|
|
|
|
case 0x1f: case 0x20: case 0x21: /* temperatures */
|
2020-11-11 14:45:07 -03:00
|
|
|
ret = VT82C686_TEMP_TO_REG(dev->values->temperatures[(addr == 0x1f) ? 2 : (addr & 1)]);
|
|
|
|
|
break;
|
2020-11-10 22:02:30 -03:00
|
|
|
|
|
|
|
|
case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: /* voltages */
|
2020-11-11 14:45:07 -03:00
|
|
|
ret = VT82C686_VOLTAGE_TO_REG(dev->values->voltages[addr - 0x22], voltage_factors[addr - 0x22]);
|
|
|
|
|
break;
|
2020-11-10 22:02:30 -03:00
|
|
|
|
|
|
|
|
case 0x29: case 0x2a: /* fan speeds */
|
2020-11-11 14:45:07 -03:00
|
|
|
ret = VT82C686_RPM_TO_REG(dev->values->fans[addr - 0x29], 1 << ((dev->regs[0x47] >> ((addr == 0x29) ? 4 : 6)) & 0x3));
|
|
|
|
|
break;
|
2020-11-10 22:02:30 -03:00
|
|
|
|
|
|
|
|
default: /* other registers */
|
2020-11-11 14:45:07 -03:00
|
|
|
ret = dev->regs[addr];
|
|
|
|
|
break;
|
2020-11-10 22:02:30 -03:00
|
|
|
}
|
2020-11-11 14:45:07 -03:00
|
|
|
|
|
|
|
|
return ret;
|
2020-10-13 19:27:48 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
vt82c686_write(uint16_t port, uint8_t val, void *priv)
|
|
|
|
|
{
|
|
|
|
|
vt82c686_t *dev = (vt82c686_t *) priv;
|
|
|
|
|
uint8_t reg = port - dev->io_base;
|
|
|
|
|
|
|
|
|
|
if ((reg == 0x41) || (reg == 0x42) || (reg == 0x45) || (reg == 0x46) || (reg == 0x48) || (reg == 0x4a) || (reg >= 0x4c))
|
|
|
|
|
return;
|
|
|
|
|
|
2020-11-10 22:02:30 -03:00
|
|
|
if ((reg == 0x40) && (val & 0x80)) {
|
2020-11-11 14:45:07 -03:00
|
|
|
val &= 0x7f;
|
2020-11-10 22:02:30 -03:00
|
|
|
vt82c686_reset(dev, 1);
|
2020-10-13 19:27:48 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dev->regs[reg] = val;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Writes to hardware monitor-related configuration space registers
|
|
|
|
|
of the VT82C686 power management function are sent here by via_pipc.c */
|
|
|
|
|
void
|
|
|
|
|
vt82c686_hwm_write(uint8_t addr, uint8_t val, void *priv)
|
|
|
|
|
{
|
|
|
|
|
vt82c686_t *dev = (vt82c686_t *) priv;
|
|
|
|
|
|
|
|
|
|
if (dev->io_base)
|
2020-10-30 20:41:15 -03:00
|
|
|
io_removehandler(dev->io_base, 0x0050,
|
2020-10-13 19:27:48 -03:00
|
|
|
vt82c686_read, NULL, NULL, vt82c686_write, NULL, NULL, dev);
|
|
|
|
|
|
|
|
|
|
switch (addr) {
|
2020-10-30 20:41:15 -03:00
|
|
|
case 0x70:
|
|
|
|
|
dev->io_base &= 0xff00;
|
|
|
|
|
dev->io_base |= val & 0x80;
|
|
|
|
|
break;
|
2020-10-13 19:27:48 -03:00
|
|
|
|
2020-10-30 20:41:15 -03:00
|
|
|
case 0x71:
|
|
|
|
|
dev->io_base &= 0x00ff;
|
|
|
|
|
dev->io_base |= val << 8;
|
|
|
|
|
break;
|
2020-10-13 19:27:48 -03:00
|
|
|
|
|
|
|
|
case 0x74:
|
|
|
|
|
dev->enable = val & 0x01;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dev->enable && dev->io_base)
|
2020-10-30 20:41:15 -03:00
|
|
|
io_sethandler(dev->io_base, 0x0050,
|
2020-10-13 19:27:48 -03:00
|
|
|
vt82c686_read, NULL, NULL, vt82c686_write, NULL, NULL, dev);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
vt82c686_reset(vt82c686_t *dev, uint8_t initialization)
|
|
|
|
|
{
|
|
|
|
|
memset(dev->regs, 0, 80);
|
|
|
|
|
|
|
|
|
|
dev->regs[0x40] = 0x08;
|
|
|
|
|
dev->regs[0x47] = 0x50;
|
2020-11-10 22:02:30 -03:00
|
|
|
dev->regs[0x4b] = 0x15;
|
2020-10-13 19:27:48 -03:00
|
|
|
|
|
|
|
|
if (!initialization)
|
2020-11-11 14:45:07 -03:00
|
|
|
vt82c686_hwm_write(0x74, 0x00, dev);
|
2020-10-13 19:27:48 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
vt82c686_close(void *priv)
|
|
|
|
|
{
|
|
|
|
|
vt82c686_t *dev = (vt82c686_t *) priv;
|
|
|
|
|
|
|
|
|
|
free(dev);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void *
|
|
|
|
|
vt82c686_init(const device_t *info)
|
|
|
|
|
{
|
|
|
|
|
vt82c686_t *dev = (vt82c686_t *) malloc(sizeof(vt82c686_t));
|
|
|
|
|
memset(dev, 0, sizeof(vt82c686_t));
|
|
|
|
|
|
2020-10-30 20:41:15 -03:00
|
|
|
/* Set default values. Since this hardware monitor has a complex voltage factor system,
|
|
|
|
|
the values struct contains voltage values *before* applying their respective factors. */
|
|
|
|
|
hwm_values_t defaults = {
|
|
|
|
|
{ /* fan speeds */
|
2020-11-10 22:02:30 -03:00
|
|
|
3000, /* usually CPU */
|
|
|
|
|
3000 /* usually Chassis */
|
2020-10-30 20:41:15 -03:00
|
|
|
}, { /* temperatures */
|
2020-11-10 22:02:30 -03:00
|
|
|
30, /* usually CPU */
|
|
|
|
|
30, /* usually System */
|
|
|
|
|
30
|
2020-10-30 20:41:15 -03:00
|
|
|
}, { /* voltages */
|
|
|
|
|
hwm_get_vcore(), /* Vcore */
|
2020-11-10 22:02:30 -03:00
|
|
|
2500, /* +2.5V */
|
|
|
|
|
3300, /* +3.3V */
|
|
|
|
|
5000, /* +5V */
|
|
|
|
|
12000 /* +12V */
|
2020-10-30 20:41:15 -03:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
hwm_values = defaults;
|
|
|
|
|
dev->values = &hwm_values;
|
2020-10-13 19:27:48 -03:00
|
|
|
|
|
|
|
|
vt82c686_reset(dev, 0);
|
|
|
|
|
|
|
|
|
|
return dev;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const device_t via_vt82c686_hwm_device = {
|
|
|
|
|
"VIA VT82C686 Integrated Hardware Monitor",
|
|
|
|
|
DEVICE_ISA,
|
|
|
|
|
0,
|
|
|
|
|
vt82c686_init, vt82c686_close, NULL,
|
2020-11-16 00:01:21 +01:00
|
|
|
{ NULL }, NULL, NULL,
|
2020-10-13 19:27:48 -03:00
|
|
|
NULL
|
|
|
|
|
};
|