- Fixed a bug with displaying incorrect temperature values. 
 - Fixed memory leak (temporary failure of dlmalloc). 
 - Small refactoring.
 - Use gnu99 to make empty functions with no return return 0.

git-svn-id: svn://kolibrios.org@9827 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
turbocat 2022-05-31 21:27:08 +00:00
parent 171a745608
commit 4237496c20
5 changed files with 104 additions and 131 deletions

View File

@ -521,7 +521,7 @@ static inline void __SysMsgBoardStr(char *text)
::"S" (text));
};
static inline void *vzalloc(unsigned long size)
static inline void *KernelZeroAlloc(unsigned long size)
{
void *mem;

View File

@ -481,7 +481,7 @@ static void amd_cache_gart(void)
if (!amd_nb_has_feature(AMD_NB_GART))
return;
flush_words = kmalloc_array(amd_northbridges.num, sizeof(u32), GFP_KERNEL);
flush_words = KernelZeroAlloc(amd_northbridges.num * sizeof(u32));
if (!flush_words) {
amd_northbridges.flags &= ~AMD_NB_GART;
pr_notice("Cannot initialize GART flush words, GART support disabled\n");

View File

@ -5,7 +5,7 @@ then
end
tup.include(HELPERDIR .. "/use_gcc.lua")
CFLAGS =[[ -Os -march=i686 -fno-ident -msse2 -fomit-frame-pointer -fno-builtin-printf -mno-stack-arg-probe -mpreferred-stack-boundary=2 -mincoming-stack-boundary=2 -mno-ms-bitfields -UWIN32 -U_WIN32 -U__WIN32__ -D_KOLIBRI -DKOLIBRI -D__KERNEL__ -DCONFIG_X86_32 -DCONFIG_DMI -DCONFIG_TINY_RCU -DCONFIG_X86_L1_CACHE_SHIFT=6 -DCONFIG_ARCH_HAS_CACHE_LINE_SIZE -DCONFIG_PRINTK -DCONFIG_PCI -DCONFIG_PCI -DCONFIG_AMD_NB -DKBUILD_MODNAME="\"k10temp"\" -I../../include -I../../include/asm -I../../include/uapi -I../../include/drm ]]
CFLAGS =[[ -std=gnu99 -Os -march=i686 -fno-ident -msse2 -fomit-frame-pointer -fno-builtin-printf -mno-stack-arg-probe -mpreferred-stack-boundary=2 -mincoming-stack-boundary=2 -mno-ms-bitfields -UWIN32 -U_WIN32 -U__WIN32__ -D_KOLIBRI -DKOLIBRI -D__KERNEL__ -DCONFIG_X86_32 -DCONFIG_DMI -DCONFIG_TINY_RCU -DCONFIG_X86_L1_CACHE_SHIFT=6 -DCONFIG_ARCH_HAS_CACHE_LINE_SIZE -DCONFIG_PRINTK -DCONFIG_PCI -DCONFIG_PCI -DCONFIG_AMD_NB -DKBUILD_MODNAME="\"k10temp"\" -I../../include -I../../include/asm -I../../include/uapi -I../../include/drm ]]
LDFLAGS = " -nostdlib -shared -s --major-os-version 0 --minor-os-version 7 --major-subsystem-version 0 --minor-subsystem-version 5 --subsystem native -T../drv.lds --image-base 0 --file-alignment 512 --section-alignment 4096 -L../../../contrib/sdk/lib -L../../ddk "

View File

@ -29,6 +29,9 @@
struct cpuinfo_x86 boot_cpu_data;
extern void init_amd_nbs(void);
extern void free_pci_devices(void);
#define MODNAME KBUILD_MODNAME ": "
#define KERNEL_SPACE 0x80000000
@ -309,7 +312,7 @@ umode_t k10temp_is_visible(const void *_data,
}
return 0444;
}
#if 0
bool has_erratum_319(struct pci_dev *pdev)
{
u32 pkg_type, reg_dram_cfg;
@ -343,7 +346,6 @@ bool has_erratum_319(struct pci_dev *pdev)
return boot_cpu_data.x86_model < 4;
}
#endif
const struct hwmon_channel_info *k10temp_info[] = {
HWMON_CHANNEL_INFO(temp,
@ -396,21 +398,20 @@ void k10temp_get_ccd_support(struct pci_dev *pdev,
int k10temp_probe(struct pci_dev *pdev, const struct pci_device_id *id, struct device *hwmon_dev)
{
// int unreliable = has_erratum_319(pdev);
int unreliable = has_erratum_319(pdev);
struct device *dev = &pdev->dev;
struct k10temp_data *data;
int i;
/* if (unreliable) {
if (!force) {
if (unreliable) {
/* if (!force) {
dev_err(dev,"unreliable CPU thermal sensor; monitoring disabled\n");
return -ENODEV;
}
dev_warn(dev,
"unreliable CPU thermal sensor; check erratum 319\n");
}
*/
data = kzalloc(sizeof(struct k10temp_data), GFP_KERNEL);
memset(data, 0x0, sizeof(struct k10temp_data));
printk(MODNAME "Unreliable CPU thermal sensor; Check erratum 319\n");
}
data = KernelZeroAlloc(sizeof(struct k10temp_data));
if (!data)
return -ENOMEM;
@ -491,11 +492,10 @@ const struct pci_device_id k10temp_id_table[] = {
{}
};
#define K10TEMP_NA (~0)
#define CHANEL_MAX 9
#define K10TEMP_NA (-1)
#define CHANEL_INPUT_MAX 10
#pragma pack(push, 1)
struct{
struct {
int Tctl;
int Tdie;
int Tccd1;
@ -510,33 +510,32 @@ struct{
int Tmax;
int Tcrit;
int Tcrit_hyst;
}k10temp_out;
#pragma pack(pop)
} k10temp_out;
struct device k10temp_device;
void read_temp_info(struct device *dev, u32 attr, int channel, int *val){
long temp=0;
if(k10temp_is_visible(dev->driver_data, hwmon_temp, attr, channel)){
k10temp_read_temp(dev, attr, channel, &temp);
*val=temp;
}else{
*val=K10TEMP_NA;
int read_temp_info(struct device *dev, unsigned attr, int channel) {
long temp = K10TEMP_NA;
if (k10temp_is_visible(dev->driver_data, hwmon_temp, attr, channel)) {
if (k10temp_read_temp(dev, attr, channel, &temp)) {
temp = K10TEMP_NA;
}
}
return (int)temp;
}
void read_all_info(struct device* dev)
{
int* k10temp_out_array = (int*)&k10temp_out;
for (int c = 0; c < CHANEL_INPUT_MAX; c++) {
k10temp_out_array[c] = read_temp_info(dev, hwmon_temp_input, c);
}
}
void read_all_info(struct device* dev){
for(int c=0; c<=CHANEL_MAX; c++){
read_temp_info(dev, hwmon_temp_input, c, (int*)&k10temp_out+c);
}
read_temp_info(dev, hwmon_temp_max, 0, &k10temp_out.Tmax);
read_temp_info(dev, hwmon_temp_crit, 0, &k10temp_out.Tcrit);
read_temp_info(dev, hwmon_temp_crit_hyst, 0, &k10temp_out.Tcrit_hyst);
}
int __stdcall service_proc(ioctl_t *my_ctl){
int __stdcall service_proc(ioctl_t *my_ctl)
{
if(!my_ctl || !my_ctl->output || (int)my_ctl->output>=KERNEL_SPACE-sizeof(k10temp_out)){
printk("k10temp: Bad address for writing data!\n");
printk(MODNAME "Bad address for writing data!\n");
return 0;
}
@ -546,34 +545,43 @@ int __stdcall service_proc(ioctl_t *my_ctl){
memcpy(my_ctl->output, &k10temp_out, sizeof(k10temp_out));
return 0;
}
printk("k10temp: Invalid buffer length!\n");
printk(MODNAME "Invalid buffer length!\n");
return 1;
}
uint32_t drvEntry(int action, char *cmdline){
if(action != 1){
uint32_t drvEntry(int action, char *cmdline)
{
if (action != 1) {
return 0;
}
pci_dev_t device;
static pci_dev_t device;
const struct pci_device_id *k10temp_id;
int err;
cpu_detect(&boot_cpu_data);
err = enum_pci_devices();
if(unlikely(err != 0)) {
printk("k10temp: Device enumeration failed!\n");
return 0;
if(unlikely(enum_pci_devices() != 0)) {
printk(MODNAME "Device enumeration failed!\n");
goto error;
}
k10temp_id = find_pci_device(&device, k10temp_id_table);
if(unlikely(k10temp_id == NULL)){
printk("k10temp: Device not found!\n");
return 0;
if (unlikely(k10temp_id == NULL)) {
printk(MODNAME "Device not found!\n");
goto error;
}
init_amd_nbs();
k10temp_probe(&device.pci_dev, k10temp_id, &k10temp_device);
return RegService("k10temp", service_proc);
k10temp_out.Tmax = read_temp_info(&k10temp_device, hwmon_temp_max, 0);
k10temp_out.Tcrit = read_temp_info(&k10temp_device, hwmon_temp_crit, 0);
k10temp_out.Tcrit_hyst = read_temp_info(&k10temp_device, hwmon_temp_crit_hyst, 0);
return RegService(MODNAME, service_proc);
error:
free_pci_devices();
return 0;
}

View File

@ -1,15 +1,6 @@
#include <syscall.h>
#include <linux/kernel.h>
#include <linux/mutex.h>
#include <linux/mod_devicetable.h>
#include <linux/slab.h>
#include <linux/pm.h>
#include <asm/msr.h>
#include <linux/pci.h>
extern int pci_scan_filter(u32 id, u32 busnr, u32 devfn);
LIST_HEAD(devices);
/* PCI control bits. Shares IORESOURCE_BITS with above PCI ROM. */
@ -20,31 +11,6 @@ LIST_HEAD(devices);
#define IORESOURCE_ROM_COPY (1<<2) /* ROM is alloc'd copy, resource field overlaid */
#define IORESOURCE_ROM_BIOS_COPY (1<<3) /* ROM is BIOS copy, resource field overlaid */
/*
* Translate the low bits of the PCI base
* to the resource type
*/
/*
//int pci_scan_filter(u32 id, u32 busnr, u32 devfn)
{
u16 vendor, device;
u32 class;
int ret = 0;
vendor = id & 0xffff;
device = (id >> 16) & 0xffff;
if(vendor == 0x15AD )
{
class = PciRead32(busnr, devfn, PCI_CLASS_REVISION);
class >>= 16;
if( class == PCI_CLASS_DISPLAY_VGA )
ret = 1;
}
return ret;
};*/
static inline unsigned int pci_calc_resource_flags(unsigned int flags)
{
@ -374,13 +340,12 @@ static pci_dev_t* pci_scan_device(u32 busnr, int devfn)
hdr = PciRead8(busnr, devfn, PCI_HEADER_TYPE);
dev = (pci_dev_t*)kzalloc(sizeof(pci_dev_t), 0);
dev = (pci_dev_t*)KernelZeroAlloc(sizeof(pci_dev_t));
if(unlikely(dev == NULL))
return NULL;
INIT_LIST_HEAD(&dev->link);
dev->pci_dev.busnr = busnr;
dev->pci_dev.devfn = devfn;
dev->pci_dev.hdr_type = hdr & 0x7f;
@ -498,9 +463,7 @@ int pci_find_capability(struct pci_dev *dev, int cap)
}
int enum_pci_devices()
int enum_pci_devices(void)
{
pci_dev_t *dev;
u32 last_bus;
@ -508,7 +471,6 @@ int enum_pci_devices()
last_bus = PciApi(1);
if( unlikely(last_bus == -1))
return -1;
@ -532,6 +494,16 @@ int enum_pci_devices()
return 0;
}
void free_pci_devices(void)
{
pci_dev_t *dev = (pci_dev_t*)devices.next;
while(&dev->link != &devices) {
pci_dev_t *temp = dev;
dev = (pci_dev_t*)dev->link.next;
KernelFree(temp);
}
}
const struct pci_device_id* find_pci_device(pci_dev_t* pdev, const struct pci_device_id *idlist)
{
pci_dev_t *dev;
@ -637,6 +609,7 @@ struct pci_dev *pci_get_class(unsigned int class, struct pci_dev *from)
return NULL;
}
int pci_bus_read_config_byte (struct pci_bus *bus, u32 devfn, int pos, u8 *value)
{
// raw_spin_lock_irqsave(&pci_lock, flags);
@ -660,10 +633,7 @@ int pci_bus_read_config_dword (struct pci_bus *bus, u32 devfn, int pos, u32 *val
{
if ( pos & 3)
return PCIBIOS_BAD_REGISTER_NUMBER;
// raw_spin_lock_irqsave(&pci_lock, flags);
*value = PciRead32(bus->number, devfn, pos);
// raw_spin_unlock_irqrestore(&pci_lock, flags);
return 0;
}
@ -671,11 +641,6 @@ int pci_bus_write_config_dword(struct pci_bus *bus, unsigned int devfn, int wher
{
if ( where & 3)
return PCIBIOS_BAD_REGISTER_NUMBER;
// raw_spin_lock_irqsave(&pci_lock, flags);
PciWrite32(bus->number, devfn,where, val);
// raw_spin_unlock_irqrestore(&pci_lock, flags);
return 0;
}