forked from KolibriOS/kolibrios
k10temp:
- 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:
parent
171a745608
commit
4237496c20
@ -521,7 +521,7 @@ static inline void __SysMsgBoardStr(char *text)
|
|||||||
::"S" (text));
|
::"S" (text));
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline void *vzalloc(unsigned long size)
|
static inline void *KernelZeroAlloc(unsigned long size)
|
||||||
{
|
{
|
||||||
void *mem;
|
void *mem;
|
||||||
|
|
||||||
|
@ -481,7 +481,7 @@ static void amd_cache_gart(void)
|
|||||||
if (!amd_nb_has_feature(AMD_NB_GART))
|
if (!amd_nb_has_feature(AMD_NB_GART))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
flush_words = kmalloc_array(amd_northbridges.num, sizeof(u32), GFP_KERNEL);
|
flush_words = KernelZeroAlloc(amd_northbridges.num * sizeof(u32));
|
||||||
if (!flush_words) {
|
if (!flush_words) {
|
||||||
amd_northbridges.flags &= ~AMD_NB_GART;
|
amd_northbridges.flags &= ~AMD_NB_GART;
|
||||||
pr_notice("Cannot initialize GART flush words, GART support disabled\n");
|
pr_notice("Cannot initialize GART flush words, GART support disabled\n");
|
||||||
|
@ -5,7 +5,7 @@ then
|
|||||||
end
|
end
|
||||||
tup.include(HELPERDIR .. "/use_gcc.lua")
|
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 "
|
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 "
|
||||||
|
|
||||||
|
@ -29,6 +29,9 @@
|
|||||||
|
|
||||||
struct cpuinfo_x86 boot_cpu_data;
|
struct cpuinfo_x86 boot_cpu_data;
|
||||||
extern void init_amd_nbs(void);
|
extern void init_amd_nbs(void);
|
||||||
|
extern void free_pci_devices(void);
|
||||||
|
|
||||||
|
#define MODNAME KBUILD_MODNAME ": "
|
||||||
|
|
||||||
#define KERNEL_SPACE 0x80000000
|
#define KERNEL_SPACE 0x80000000
|
||||||
|
|
||||||
@ -127,7 +130,7 @@ const struct tctl_offset tctl_offset_table[] = {
|
|||||||
|
|
||||||
void read_htcreg_pci(struct pci_dev *pdev, u32 *regval)
|
void read_htcreg_pci(struct pci_dev *pdev, u32 *regval)
|
||||||
{
|
{
|
||||||
pci_read_config_dword(pdev, REG_HARDWARE_THERMAL_CONTROL, regval);
|
pci_read_config_dword(pdev, REG_HARDWARE_THERMAL_CONTROL, regval);
|
||||||
}
|
}
|
||||||
|
|
||||||
void read_tempreg_pci(struct pci_dev *pdev, u32 *regval)
|
void read_tempreg_pci(struct pci_dev *pdev, u32 *regval)
|
||||||
@ -309,7 +312,7 @@ umode_t k10temp_is_visible(const void *_data,
|
|||||||
}
|
}
|
||||||
return 0444;
|
return 0444;
|
||||||
}
|
}
|
||||||
#if 0
|
|
||||||
bool has_erratum_319(struct pci_dev *pdev)
|
bool has_erratum_319(struct pci_dev *pdev)
|
||||||
{
|
{
|
||||||
u32 pkg_type, reg_dram_cfg;
|
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;
|
return boot_cpu_data.x86_model < 4;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
const struct hwmon_channel_info *k10temp_info[] = {
|
const struct hwmon_channel_info *k10temp_info[] = {
|
||||||
HWMON_CHANNEL_INFO(temp,
|
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 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 device *dev = &pdev->dev;
|
||||||
struct k10temp_data *data;
|
struct k10temp_data *data;
|
||||||
int i;
|
int i;
|
||||||
/* if (unreliable) {
|
if (unreliable) {
|
||||||
if (!force) {
|
/* if (!force) {
|
||||||
dev_err(dev,"unreliable CPU thermal sensor; monitoring disabled\n");
|
dev_err(dev,"unreliable CPU thermal sensor; monitoring disabled\n");
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
dev_warn(dev,
|
|
||||||
"unreliable CPU thermal sensor; check erratum 319\n");
|
|
||||||
}
|
|
||||||
*/
|
*/
|
||||||
data = kzalloc(sizeof(struct k10temp_data), GFP_KERNEL);
|
printk(MODNAME "Unreliable CPU thermal sensor; Check erratum 319\n");
|
||||||
memset(data, 0x0, sizeof(struct k10temp_data));
|
}
|
||||||
|
|
||||||
|
data = KernelZeroAlloc(sizeof(struct k10temp_data));
|
||||||
if (!data)
|
if (!data)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
@ -491,89 +492,96 @@ const struct pci_device_id k10temp_id_table[] = {
|
|||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
#define K10TEMP_NA (~0)
|
#define K10TEMP_NA (-1)
|
||||||
#define CHANEL_MAX 9
|
#define CHANEL_INPUT_MAX 10
|
||||||
|
|
||||||
#pragma pack(push, 1)
|
struct {
|
||||||
struct{
|
int Tctl;
|
||||||
int Tctl;
|
int Tdie;
|
||||||
int Tdie;
|
int Tccd1;
|
||||||
int Tccd1;
|
int Tccd2;
|
||||||
int Tccd2;
|
int Tccd3;
|
||||||
int Tccd3;
|
int Tccd4;
|
||||||
int Tccd4;
|
int Tccd5;
|
||||||
int Tccd5;
|
int Tccd6;
|
||||||
int Tccd6;
|
int Tccd7;
|
||||||
int Tccd7;
|
int Tccd8;
|
||||||
int Tccd8;
|
|
||||||
|
int Tmax;
|
||||||
int Tmax;
|
int Tcrit;
|
||||||
int Tcrit;
|
int Tcrit_hyst;
|
||||||
int Tcrit_hyst;
|
} k10temp_out;
|
||||||
}k10temp_out;
|
|
||||||
#pragma pack(pop)
|
|
||||||
|
|
||||||
struct device k10temp_device;
|
struct device k10temp_device;
|
||||||
|
|
||||||
void read_temp_info(struct device *dev, u32 attr, int channel, int *val){
|
int read_temp_info(struct device *dev, unsigned attr, int channel) {
|
||||||
long temp=0;
|
long temp = K10TEMP_NA;
|
||||||
if(k10temp_is_visible(dev->driver_data, hwmon_temp, attr, channel)){
|
if (k10temp_is_visible(dev->driver_data, hwmon_temp, attr, channel)) {
|
||||||
k10temp_read_temp(dev, attr, channel, &temp);
|
if (k10temp_read_temp(dev, attr, channel, &temp)) {
|
||||||
*val=temp;
|
temp = K10TEMP_NA;
|
||||||
}else{
|
}
|
||||||
*val=K10TEMP_NA;
|
}
|
||||||
}
|
return (int)temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void read_all_info(struct device* dev){
|
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);
|
int* k10temp_out_array = (int*)&k10temp_out;
|
||||||
}
|
for (int c = 0; c < CHANEL_INPUT_MAX; c++) {
|
||||||
read_temp_info(dev, hwmon_temp_max, 0, &k10temp_out.Tmax);
|
k10temp_out_array[c] = read_temp_info(dev, hwmon_temp_input, c);
|
||||||
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");
|
if(!my_ctl || !my_ctl->output || (int)my_ctl->output>=KERNEL_SPACE-sizeof(k10temp_out)){
|
||||||
return 0;
|
printk(MODNAME "Bad address for writing data!\n");
|
||||||
}
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
read_all_info(&k10temp_device);
|
read_all_info(&k10temp_device);
|
||||||
|
|
||||||
if(my_ctl->out_size == sizeof(k10temp_out)){
|
if(my_ctl->out_size == sizeof(k10temp_out)){
|
||||||
memcpy(my_ctl->output, &k10temp_out, sizeof(k10temp_out));
|
memcpy(my_ctl->output, &k10temp_out, sizeof(k10temp_out));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
printk("k10temp: Invalid buffer length!\n");
|
printk(MODNAME "Invalid buffer length!\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t drvEntry(int action, char *cmdline){
|
uint32_t drvEntry(int action, char *cmdline)
|
||||||
if(action != 1){
|
{
|
||||||
return 0;
|
if (action != 1) {
|
||||||
}
|
return 0;
|
||||||
pci_dev_t device;
|
}
|
||||||
const struct pci_device_id *k10temp_id;
|
|
||||||
int err;
|
static pci_dev_t device;
|
||||||
|
const struct pci_device_id *k10temp_id;
|
||||||
|
|
||||||
cpu_detect(&boot_cpu_data);
|
cpu_detect(&boot_cpu_data);
|
||||||
|
|
||||||
err = enum_pci_devices();
|
if(unlikely(enum_pci_devices() != 0)) {
|
||||||
if(unlikely(err != 0)) {
|
printk(MODNAME "Device enumeration failed!\n");
|
||||||
printk("k10temp: Device enumeration failed!\n");
|
goto error;
|
||||||
return 0;
|
}
|
||||||
}
|
|
||||||
|
k10temp_id = find_pci_device(&device, k10temp_id_table);
|
||||||
|
|
||||||
k10temp_id = find_pci_device(&device, k10temp_id_table);
|
if (unlikely(k10temp_id == NULL)) {
|
||||||
|
printk(MODNAME "Device not found!\n");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
if(unlikely(k10temp_id == NULL)){
|
init_amd_nbs();
|
||||||
printk("k10temp: Device not found!\n");
|
k10temp_probe(&device.pci_dev, k10temp_id, &k10temp_device);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
init_amd_nbs();
|
k10temp_out.Tmax = read_temp_info(&k10temp_device, hwmon_temp_max, 0);
|
||||||
k10temp_probe(&device.pci_dev, k10temp_id, &k10temp_device);
|
k10temp_out.Tcrit = read_temp_info(&k10temp_device, hwmon_temp_crit, 0);
|
||||||
return RegService("k10temp", service_proc);
|
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;
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,6 @@
|
|||||||
#include <syscall.h>
|
#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>
|
#include <linux/pci.h>
|
||||||
|
|
||||||
extern int pci_scan_filter(u32 id, u32 busnr, u32 devfn);
|
|
||||||
|
|
||||||
LIST_HEAD(devices);
|
LIST_HEAD(devices);
|
||||||
|
|
||||||
/* PCI control bits. Shares IORESOURCE_BITS with above PCI ROM. */
|
/* 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_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 */
|
#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)
|
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);
|
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))
|
if(unlikely(dev == NULL))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
INIT_LIST_HEAD(&dev->link);
|
INIT_LIST_HEAD(&dev->link);
|
||||||
|
|
||||||
|
|
||||||
dev->pci_dev.busnr = busnr;
|
dev->pci_dev.busnr = busnr;
|
||||||
dev->pci_dev.devfn = devfn;
|
dev->pci_dev.devfn = devfn;
|
||||||
dev->pci_dev.hdr_type = hdr & 0x7f;
|
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(void)
|
||||||
|
|
||||||
int enum_pci_devices()
|
|
||||||
{
|
{
|
||||||
pci_dev_t *dev;
|
pci_dev_t *dev;
|
||||||
u32 last_bus;
|
u32 last_bus;
|
||||||
@ -508,7 +471,6 @@ int enum_pci_devices()
|
|||||||
|
|
||||||
last_bus = PciApi(1);
|
last_bus = PciApi(1);
|
||||||
|
|
||||||
|
|
||||||
if( unlikely(last_bus == -1))
|
if( unlikely(last_bus == -1))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@ -532,6 +494,16 @@ int enum_pci_devices()
|
|||||||
return 0;
|
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)
|
const struct pci_device_id* find_pci_device(pci_dev_t* pdev, const struct pci_device_id *idlist)
|
||||||
{
|
{
|
||||||
pci_dev_t *dev;
|
pci_dev_t *dev;
|
||||||
@ -637,6 +609,7 @@ struct pci_dev *pci_get_class(unsigned int class, struct pci_dev *from)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int pci_bus_read_config_byte (struct pci_bus *bus, u32 devfn, int pos, u8 *value)
|
int pci_bus_read_config_byte (struct pci_bus *bus, u32 devfn, int pos, u8 *value)
|
||||||
{
|
{
|
||||||
// raw_spin_lock_irqsave(&pci_lock, flags);
|
// 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)
|
if ( pos & 3)
|
||||||
return PCIBIOS_BAD_REGISTER_NUMBER;
|
return PCIBIOS_BAD_REGISTER_NUMBER;
|
||||||
|
|
||||||
// raw_spin_lock_irqsave(&pci_lock, flags);
|
|
||||||
*value = PciRead32(bus->number, devfn, pos);
|
*value = PciRead32(bus->number, devfn, pos);
|
||||||
// raw_spin_unlock_irqrestore(&pci_lock, flags);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -671,11 +641,6 @@ int pci_bus_write_config_dword(struct pci_bus *bus, unsigned int devfn, int wher
|
|||||||
{
|
{
|
||||||
if ( where & 3)
|
if ( where & 3)
|
||||||
return PCIBIOS_BAD_REGISTER_NUMBER;
|
return PCIBIOS_BAD_REGISTER_NUMBER;
|
||||||
|
|
||||||
// raw_spin_lock_irqsave(&pci_lock, flags);
|
|
||||||
PciWrite32(bus->number, devfn,where, val);
|
PciWrite32(bus->number, devfn,where, val);
|
||||||
// raw_spin_unlock_irqrestore(&pci_lock, flags);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user