2020-05-24 15:30:55 -05:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#ifndef PCI_H
|
|
|
|
#define PCI_H
|
2022-02-19 10:17:40 -06:00
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
*
|
2021-12-05 08:15:37 -06:00
|
|
|
* Provides functions to perform PCI configuration space reads and writes.
|
2020-05-24 15:30:55 -05:00
|
|
|
*
|
2022-02-19 13:56:55 -06:00
|
|
|
*//*
|
2022-02-19 10:17:40 -06:00
|
|
|
* Copyright (C) 2020-2022 Martin Whitaker.
|
2020-05-24 15:30:55 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2021-12-05 08:15:37 -06:00
|
|
|
#define PCI_MAX_BUS 256
|
|
|
|
#define PCI_MAX_DEV 32
|
|
|
|
#define PCI_MAX_FUNC 8
|
2020-05-24 15:30:55 -05:00
|
|
|
|
2022-02-19 10:17:40 -06:00
|
|
|
/**
|
2021-12-05 08:15:37 -06:00
|
|
|
* Initialises the PCI access support.
|
|
|
|
*/
|
|
|
|
void pci_init(void);
|
|
|
|
|
2022-02-19 10:17:40 -06:00
|
|
|
/**
|
2021-12-05 08:15:37 -06:00
|
|
|
* Returns an 8 bit value read from the specified bus+device+function+register
|
|
|
|
* address in the PCI configuration address space.
|
|
|
|
*/
|
|
|
|
uint8_t pci_config_read8(int bus, int dev, int func, int reg);
|
2020-05-24 15:30:55 -05:00
|
|
|
|
2022-02-19 10:17:40 -06:00
|
|
|
/**
|
2021-12-05 08:15:37 -06:00
|
|
|
* Returns a 16 bit value read from the specified bus+device+function+register
|
|
|
|
* address in the PCI configuration address space. The address must be 16-bit
|
|
|
|
* aligned.
|
|
|
|
*/
|
|
|
|
uint16_t pci_config_read16(int bus, int dev, int func, int reg);
|
|
|
|
|
2022-02-19 10:17:40 -06:00
|
|
|
/**
|
2021-12-05 08:15:37 -06:00
|
|
|
* Returns a 32 bit value read from the specified bus+device+function+register
|
|
|
|
* address in the PCI configuration address space. The address must be 32-bit
|
|
|
|
* aligned.
|
|
|
|
*/
|
|
|
|
uint32_t pci_config_read32(int bus, int dev, int func, int reg);
|
|
|
|
|
2022-02-19 10:17:40 -06:00
|
|
|
/**
|
2021-12-05 08:15:37 -06:00
|
|
|
* Writes an 8 bit value to the specified bus+device+function+register address
|
|
|
|
* in the PCI configuration address space.
|
|
|
|
*/
|
|
|
|
void pci_config_write8(int bus, int dev, int func, int reg, uint8_t value);
|
|
|
|
|
2022-02-19 10:17:40 -06:00
|
|
|
/**
|
2021-12-05 08:15:37 -06:00
|
|
|
* Writes a 16 bit value to the specified bus+device+function+register address
|
|
|
|
* in the PCI configuration address space. The address must be 16-bit aligned.
|
|
|
|
*/
|
|
|
|
void pci_config_write16(int bus, int dev, int func, int reg, uint16_t value);
|
|
|
|
|
2022-02-19 10:17:40 -06:00
|
|
|
/**
|
2021-12-05 08:15:37 -06:00
|
|
|
* Writes a 32 bit value to the specified bus+device+function+register address
|
|
|
|
* in the PCI configuration address space. The address must be 32-bit aligned.
|
|
|
|
*/
|
|
|
|
void pci_config_write32(int bus, int dev, int func, int reg, uint32_t value);
|
2020-05-24 15:30:55 -05:00
|
|
|
|
2022-03-09 18:23:29 -06:00
|
|
|
|
2022-05-20 06:23:25 -05:00
|
|
|
/**
|
|
|
|
* Basic LPC Functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
void lpc_outb(uint8_t cmd, uint8_t data);
|
|
|
|
uint8_t lpc_inb(uint8_t reg);
|
|
|
|
|
2022-03-09 18:23:29 -06:00
|
|
|
/*
|
|
|
|
* Add some SNM related function (S.DEMEULEMEESTER)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define SMN_SMUIO_THM 0x00059800
|
|
|
|
#define SMN_THM_TCON_CUR_TMP (SMN_SMUIO_THM + 0x00)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Read & Write to AMD Family 17h SNM
|
|
|
|
*/
|
|
|
|
uint32_t amd_smn_read(uint32_t adr);
|
|
|
|
void amd_smn_write(uint32_t adr, uint32_t data);
|
|
|
|
|
2020-05-24 15:30:55 -05:00
|
|
|
#endif // PCI_H
|