2022-03-16 19:43:09 -05:00
|
|
|
#ifndef _SMBUS_H_
|
|
|
|
#define _SMBUS_H_
|
2022-03-13 23:35:36 -05:00
|
|
|
/**
|
2022-03-16 19:43:09 -05:00
|
|
|
* SPDX-License-Identifier: GPL-2.0
|
|
|
|
*
|
2022-03-13 23:35:36 -05:00
|
|
|
* \file
|
|
|
|
*
|
|
|
|
* Provides functions for reading SPD via SMBUS
|
|
|
|
*
|
2023-02-19 10:29:56 -06:00
|
|
|
* Copyright (C) 2004-2023 Sam Demeulemeester.
|
2022-03-13 23:35:36 -05:00
|
|
|
*/
|
|
|
|
|
2022-03-23 21:20:29 -05:00
|
|
|
#define I2C_WRITE 0
|
|
|
|
#define I2C_READ 1
|
|
|
|
|
2022-05-23 18:00:52 -05:00
|
|
|
#define SPD5_MR11 11
|
|
|
|
|
2022-03-16 19:43:09 -05:00
|
|
|
/* i801 Hosts Addresses */
|
|
|
|
#define SMBHSTSTS smbusbase
|
|
|
|
#define SMBHSTCNT smbusbase + 2
|
|
|
|
#define SMBHSTCMD smbusbase + 3
|
|
|
|
#define SMBHSTADD smbusbase + 4
|
|
|
|
#define SMBHSTDAT0 smbusbase + 5
|
|
|
|
#define SMBHSTDAT1 smbusbase + 6
|
|
|
|
#define SMBBLKDAT smbusbase + 7
|
|
|
|
#define SMBPEC smbusbase + 8
|
|
|
|
#define SMBAUXSTS smbusbase + 12
|
2022-03-23 21:20:29 -05:00
|
|
|
#define SMBAUXCTL smbusbase + 13
|
2022-03-16 19:43:09 -05:00
|
|
|
|
|
|
|
/* i801 Hosts Status register bits */
|
|
|
|
#define SMBHSTSTS_BYTE_DONE 0x80
|
|
|
|
#define SMBHSTSTS_INUSE_STS 0x40
|
|
|
|
#define SMBHSTSTS_SMBALERT_STS 0x20
|
|
|
|
#define SMBHSTSTS_FAILED 0x10
|
|
|
|
#define SMBHSTSTS_BUS_ERR 0x08
|
|
|
|
#define SMBHSTSTS_DEV_ERR 0x04
|
|
|
|
#define SMBHSTSTS_INTR 0x02
|
|
|
|
#define SMBHSTSTS_HOST_BUSY 0x01
|
|
|
|
|
2022-03-23 21:20:29 -05:00
|
|
|
#define SMBHSTCNT_QUICK 0x00
|
|
|
|
#define SMBHSTCNT_BYTE 0x04
|
|
|
|
#define SMBHSTCNT_BYTE_DATA 0x08
|
|
|
|
#define SMBHSTCNT_WORD_DATA 0x0C
|
|
|
|
#define SMBHSTCNT_BLOCK_DATA 0x14
|
|
|
|
#define SMBHSTCNT_I2C_BLOCK_DATA 0x18
|
|
|
|
#define SMBHSTCNT_LAST_BYTE 0x20
|
|
|
|
#define SMBHSTCNT_START 0x40
|
2022-03-16 19:43:09 -05:00
|
|
|
|
2022-03-27 16:47:57 -05:00
|
|
|
/* AMD-Specific constants */
|
|
|
|
#define AMD_INDEX_IO_PORT 0xCD6
|
|
|
|
#define AMD_DATA_IO_PORT 0xCD7
|
2022-05-20 11:07:22 -05:00
|
|
|
#define AMD_SMBUS_BASE_REG 0x2C
|
2022-03-27 16:47:57 -05:00
|
|
|
#define AMD_PM_INDEX 0x00
|
|
|
|
|
2022-05-23 18:00:52 -05:00
|
|
|
/* nVidia-Specific constants */
|
|
|
|
#define NV_SMBUS_ADR_REG 0x20
|
|
|
|
#define NV_OLD_SMBUS_ADR_REG 0x50
|
|
|
|
|
|
|
|
#define NVSMBCNT smbusbase + 0
|
|
|
|
#define NVSMBSTS smbusbase + 1
|
|
|
|
#define NVSMBADD smbusbase + 2
|
|
|
|
#define NVSMBCMD smbusbase + 3
|
|
|
|
#define NVSMBDAT(x) (smbusbase + 4 + (x))
|
|
|
|
|
|
|
|
#define NVSMBCNT_WRITE 0x00
|
|
|
|
#define NVSMBCNT_READ 0x01
|
|
|
|
#define NVSMBCNT_QUICK 0x02
|
|
|
|
#define NVSMBCNT_BYTE 0x04
|
|
|
|
#define NVSMBCNT_BYTE_DATA 0x06
|
|
|
|
#define NVSMBCNT_WORD_DATA 0x08
|
|
|
|
|
|
|
|
#define NVSMBSTS_DONE 0x80
|
|
|
|
#define NVSMBSTS_ALRM 0x40
|
|
|
|
#define NVSMBSTS_RES 0x20
|
|
|
|
#define NVSMBSTS_STATUS 0x1f
|
2022-03-16 19:43:09 -05:00
|
|
|
|
2023-02-20 11:31:33 -06:00
|
|
|
/* ALi-Specific constants (M1563 & newer) */
|
2023-02-19 10:29:56 -06:00
|
|
|
#define ALI_SMBHSTCNT_SIZEMASK 0x03
|
|
|
|
#define ALI_SMBHSTSTS_BAD 0x1C
|
|
|
|
|
|
|
|
#define ALI_SMBHSTCNT_QUICK 0x00
|
|
|
|
#define ALI_SMBHSTCNT_BYTE 0x01
|
|
|
|
#define ALI_SMBHSTCNT_BYTE_DATA 0x02
|
|
|
|
#define ALI_SMBHSTCNT_WORD_DATA 0x03
|
|
|
|
#define ALI_SMBHSTCNT_KILL 0x04
|
|
|
|
#define ALI_SMBHSTCNT_BLOCK 0x05
|
|
|
|
|
2023-02-20 11:31:33 -06:00
|
|
|
/* ALi-Specific constants (M1543 & older) */
|
|
|
|
#define ALI_OLD_SMBHSTSTS_BAD 0xE0
|
|
|
|
#define ALI_OLD_SMBHSTSTS_BUSY 0x08
|
|
|
|
#define ALI_OLD_SMBHSTCNT_BYTE_DATA 0x20
|
|
|
|
|
|
|
|
#define ALI_OLD_SMBHSTCNT smbusbase + 1
|
|
|
|
#define ALI_OLD_SMBHSTSTART smbusbase + 2
|
|
|
|
#define ALI_OLD_SMBHSTADD smbusbase + 3
|
|
|
|
#define ALI_OLD_SMBHSTDAT0 smbusbase + 4
|
|
|
|
#define ALI_OLD_SMBHSTCMD smbusbase + 7
|
|
|
|
|
2023-01-23 08:01:48 -06:00
|
|
|
#define PIIX4_SMB_BASE_ADR_DEFAULT 0x90
|
|
|
|
#define PIIX4_SMB_BASE_ADR_VIAPRO 0xD0
|
2023-02-19 10:29:56 -06:00
|
|
|
#define PIIX4_SMB_BASE_ADR_ALI1563 0x80
|
2023-02-20 11:31:33 -06:00
|
|
|
#define PIIX4_SMB_BASE_ADR_ALI1543 0x14
|
2023-01-23 08:01:48 -06:00
|
|
|
|
2022-06-06 03:24:45 -05:00
|
|
|
struct pci_smbus_controller {
|
2022-03-16 19:43:09 -05:00
|
|
|
unsigned vendor;
|
|
|
|
unsigned device;
|
2022-03-23 21:20:29 -05:00
|
|
|
void (*get_adr)(void);
|
2022-03-16 19:43:09 -05:00
|
|
|
};
|
|
|
|
|
2022-03-13 23:35:36 -05:00
|
|
|
/**
|
Split SPD parsing and printing code from smbus.c to spd.c (#426)
* Split SPD parsing and printing code from smbus.c to spd.c
Move all SPD parsing and printing code from smbus.{c,h} to spd.{c,h}.
Introduce parse_spd() function, moving the parse_spd_* selection logic
from print_smbus_startup_info(), allowing to keep parse_spd_* static.
Remove static from get_spd() and update print_smbus_startup_info()
to use parse_spd() which also simplifies the code flow.
Move LINE_SPD into display.h and rename it to ROW_SPD. Update print_spdi()
to use explicit row number where the SPD info needs to be printed.
Rename ram_info into ram_info_t, rename print_smbus_startup_info()
into print_spd_startup_info.
Do not initialize ram.freq to 0, this is the initial value already.
Do not set curspd.isValid to False, the first thing that parse_spd()
does is setting the entire struct to 0, that also sets isValid to False.
print_spd_startup_info() from smbus.c is technically a skeleton now
so each arch can have its own version, adjusted as needed. Once
LA64 changes land, we can think how we can even make it arch agnostic.
* Add -fexcess-precision=standard to CFLAGS for build(32,64)/Makefile
Recent switch from -std=c11 to -std=gnu11 done in 53ca89f ("Add
initial NUMA awareness support") introduced a regression in SPD
parsing code (and potentially in other places) due to change of
floating point precision. Restore the original behavior by
adding -fexcess-precision=standard to CFLAGS.
Bug: https://github.com/memtest86plus/memtest86plus/issues/425
Fixes: https://github.com/memtest86plus/memtest86plus/commit/53ca89f8aeeea649a1b8c2d2d14ec121f7025f54
2024-08-07 19:41:19 -05:00
|
|
|
* Print SPD Info
|
2022-03-13 23:35:36 -05:00
|
|
|
*/
|
|
|
|
|
Split SPD parsing and printing code from smbus.c to spd.c (#426)
* Split SPD parsing and printing code from smbus.c to spd.c
Move all SPD parsing and printing code from smbus.{c,h} to spd.{c,h}.
Introduce parse_spd() function, moving the parse_spd_* selection logic
from print_smbus_startup_info(), allowing to keep parse_spd_* static.
Remove static from get_spd() and update print_smbus_startup_info()
to use parse_spd() which also simplifies the code flow.
Move LINE_SPD into display.h and rename it to ROW_SPD. Update print_spdi()
to use explicit row number where the SPD info needs to be printed.
Rename ram_info into ram_info_t, rename print_smbus_startup_info()
into print_spd_startup_info.
Do not initialize ram.freq to 0, this is the initial value already.
Do not set curspd.isValid to False, the first thing that parse_spd()
does is setting the entire struct to 0, that also sets isValid to False.
print_spd_startup_info() from smbus.c is technically a skeleton now
so each arch can have its own version, adjusted as needed. Once
LA64 changes land, we can think how we can even make it arch agnostic.
* Add -fexcess-precision=standard to CFLAGS for build(32,64)/Makefile
Recent switch from -std=c11 to -std=gnu11 done in 53ca89f ("Add
initial NUMA awareness support") introduced a regression in SPD
parsing code (and potentially in other places) due to change of
floating point precision. Restore the original behavior by
adding -fexcess-precision=standard to CFLAGS.
Bug: https://github.com/memtest86plus/memtest86plus/issues/425
Fixes: https://github.com/memtest86plus/memtest86plus/commit/53ca89f8aeeea649a1b8c2d2d14ec121f7025f54
2024-08-07 19:41:19 -05:00
|
|
|
void print_spd_startup_info(void);
|
|
|
|
|
|
|
|
uint8_t get_spd(uint8_t slot_idx, uint16_t spd_adr);
|
2022-03-13 23:35:36 -05:00
|
|
|
|
2022-08-15 10:51:48 -05:00
|
|
|
#endif // SMBUS_H
|