Skip to content

Commit 071f783

Browse files
committed
Implementing I2C for AMD/SB-RMI queries [EPYC/Naples]
1 parent f464bc1 commit 071f783

7 files changed

+498
-120
lines changed

amdmsr.h

+49-77
Original file line numberDiff line numberDiff line change
@@ -183,85 +183,21 @@ enum {
183183
#define IS_HSMP_OOO(_rx) (_rx == HSMP_UNSPECIFIED \
184184
|| (_rx >= HSMP_FAIL_BGN && _rx <= HSMP_FAIL_END))
185185

186-
/* Sources: PPR for AMD Family 17h */
187-
#define AMD_FCH_PM_CSTATE_EN 0x0000007e
188-
189-
#define AMD_FCH_READ16(_data, _reg) \
190-
({ \
191-
__asm__ volatile \
192-
( \
193-
"movl %1 , %%eax" "\n\t" \
194-
"movl $0xcd6 , %%edx" "\n\t" \
195-
"outl %%eax , %%dx" "\n\t" \
196-
"movl $0xcd7 , %%edx" "\n\t" \
197-
"inw %%dx , %%ax" "\n\t" \
198-
"movw %%ax , %0" \
199-
: "=m" (_data) \
200-
: "i" (_reg) \
201-
: "%rax", "%rdx", "memory" \
202-
); \
203-
})
204-
205-
#define AMD_FCH_WRITE16(_data, _reg) \
206-
({ \
207-
__asm__ volatile \
208-
( \
209-
"movl %1 , %%eax" "\n\t" \
210-
"movl $0xcd6 , %%edx" "\n\t" \
211-
"outl %%eax , %%dx" "\n\t" \
212-
"movw %0 , %%ax" "\n\t" \
213-
"movl $0xcd7 , %%edx" "\n\t" \
214-
"outw %%ax , %%dx" "\n\t" \
215-
: \
216-
: "im" (_data), \
217-
"i" (_reg) \
218-
: "%rax", "%rdx", "memory" \
219-
); \
220-
})
221-
222-
#define AMD_FCH_PM_Read16(IndexRegister, DataRegister) \
223-
({ \
224-
unsigned int tries = BIT_IO_RETRIES_COUNT; \
225-
unsigned char ret; \
226-
do { \
227-
ret = BIT_ATOM_TRYLOCK( BUS_LOCK, \
228-
PRIVATE(OF(AMD_FCH_LOCK)), \
229-
ATOMIC_SEED) ; \
230-
if (ret == 0) { \
231-
udelay(BIT_IO_DELAY_INTERVAL); \
232-
} else { \
233-
AMD_FCH_READ16(DataRegister.value, IndexRegister); \
234-
\
235-
BIT_ATOM_UNLOCK(BUS_LOCK, \
236-
PRIVATE(OF(AMD_FCH_LOCK)), \
237-
ATOMIC_SEED); \
238-
} \
239-
tries--; \
240-
} while ( (tries != 0) && (ret != 1) ); \
241-
})
242-
243-
#define AMD_FCH_PM_Write16(IndexRegister , DataRegister) \
244-
({ \
245-
unsigned int tries = BIT_IO_RETRIES_COUNT; \
246-
unsigned char ret; \
247-
do { \
248-
ret = BIT_ATOM_TRYLOCK( BUS_LOCK, \
249-
PRIVATE(OF(AMD_FCH_LOCK)), \
250-
ATOMIC_SEED ); \
251-
if (ret == 0) { \
252-
udelay(BIT_IO_DELAY_INTERVAL); \
253-
} else { \
254-
AMD_FCH_WRITE16(DataRegister.value, IndexRegister); \
255-
\
256-
BIT_ATOM_UNLOCK(BUS_LOCK, \
257-
PRIVATE(OF(AMD_FCH_LOCK)), \
258-
ATOMIC_SEED); \
259-
} \
260-
tries--; \
261-
} while ( (tries != 0) && (ret != 1) ); \
262-
})
186+
enum SBRMI_REGISTER {
187+
SBRMI_REVISION = 0x0,
188+
SBRMI_CONTROL = 0x1,
189+
SBRMI_STATUS = 0x2,
190+
SBRMI_OUT_BOUND = 0x30,
191+
SBRMI_IN_BOUND = 0x38,
192+
SBRMI_INTERRUPT = 0x40
193+
};
263194

195+
enum SBRMI_FUNC {
196+
SBRMI_RD_PKG_TDP= 0x1, /* Package power cTDP[31:0] (mWatts) */
197+
SBRMI_WR_PKG_TDP= 0x2, /* SoC package power [31:0] (mWatts) */
198+
};
264199

200+
/* Sources: BKDG for AMD Families 0Fh, 10h up to 16h */
265201
const struct {
266202
unsigned int MCF,
267203
PCF[5];
@@ -1746,3 +1682,39 @@ typedef union
17461682
VID : 32-24; /* Voltage ID */
17471683
};
17481684
} AMD_17_CORE_VID;
1685+
1686+
/* Sources: Advanced Platform Management Link (APML) Specification */
1687+
typedef union
1688+
{ /* I2C: address = 0x0 */
1689+
unsigned char value;
1690+
struct {
1691+
unsigned char
1692+
Revision : 8-0;
1693+
};
1694+
} AMD_SBRMI_REVISION;
1695+
1696+
typedef union
1697+
{ /* I2C: address = 0x1 */
1698+
unsigned char value;
1699+
struct {
1700+
unsigned char
1701+
AlertMask : 1-0,
1702+
AraDis : 2-1,
1703+
TimeoutDis : 3-2,
1704+
BlkRWEn : 4-3,
1705+
SwAlertMask : 5-4,
1706+
ReservedBits : 7-5,
1707+
PECEn : 8-7;
1708+
};
1709+
} AMD_SBRMI_CONTROL;
1710+
1711+
typedef union
1712+
{ /* I2C: address = 0x2 */
1713+
unsigned char value;
1714+
struct {
1715+
unsigned char
1716+
AlertSts : 1-0,
1717+
SwAlertSts : 2-1,
1718+
ReservedBits : 8-2;
1719+
};
1720+
} AMD_SBRMI_STATUS;

corefreq-api.h

+16-6
Original file line numberDiff line numberDiff line change
@@ -784,13 +784,18 @@ typedef struct
784784
} Uncore;
785785
} Delta __attribute__ ((aligned (8)));
786786

787-
struct
787+
union
788788
{
789-
union {
790-
UNCORE_GLOBAL_PERF_CONTROL Uncore_GlobalPerfControl;
791-
UNCORE_PMON_GLOBAL_CONTROL Uncore_PMonGlobalControl;
792-
};
793-
UNCORE_FIXED_PERF_CONTROL Uncore_FixedPerfControl;
789+
struct {
790+
union {
791+
UNCORE_GLOBAL_PERF_CONTROL Uncore_GlobalPerfControl;
792+
UNCORE_PMON_GLOBAL_CONTROL Uncore_PMonGlobalControl;
793+
};
794+
UNCORE_FIXED_PERF_CONTROL Uncore_FixedPerfControl;
795+
} Intel;
796+
struct {
797+
AMD_SBRMI_CONTROL SBRMI_Control;
798+
} AMD;
794799
} SaveArea;
795800

796801
FEATURES Features;
@@ -886,6 +891,11 @@ typedef struct
886891
Experimental,
887892
HotPlug,
888893
PCI;
894+
struct {
895+
unsigned int PFM : 1-0,
896+
I2C : 2-1,
897+
_pad32 : 32-2;
898+
};
889899
KERNEL_DRIVER Driver;
890900
} Registration;
891901

corefreq.h

+5
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,11 @@ typedef struct
463463
Experimental,/* 0: Disable, 1: Enable */
464464
HotPlug, /* < 0: Disable, Other: Enable */
465465
PCI; /* < 0: Disable, other: Enable */
466+
struct { /* = 0: Disable, 1: Enable */
467+
unsigned int PFM : 1-0,
468+
I2C : 2-1,
469+
_pad32 : 32-2;
470+
};
466471
KERNEL_DRIVER Driver; /*0:Disable, 1:Enable, 2:Full-control*/
467472
} Registration;
468473

corefreqd.c

+2
Original file line numberDiff line numberDiff line change
@@ -1753,6 +1753,8 @@ void Package_Update(SHM_STRUCT *Shm, RO(PROC) *RO(Proc), RW(PROC) *RW(Proc))
17531753
Shm->Registration.Experimental = RO(Proc)->Registration.Experimental;
17541754
Shm->Registration.HotPlug = RO(Proc)->Registration.HotPlug;
17551755
Shm->Registration.PCI = RO(Proc)->Registration.PCI;
1756+
Shm->Registration.PFM = RO(Proc)->Registration.PFM;
1757+
Shm->Registration.I2C = RO(Proc)->Registration.I2C;
17561758
BITSTOR(LOCKLESS, Shm->Registration.NMI, RO(Proc)->Registration.NMI);
17571759
Shm->Registration.Driver = RO(Proc)->Registration.Driver;
17581760
/* Copy the timer interval delay. */

0 commit comments

Comments
 (0)