Rev 9079 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 9079 | Rev 9100 | ||
---|---|---|---|
Line 11... | Line 11... | ||
11 | * convert raw register values is from https://github.com/ocerman/zenpower. |
11 | * convert raw register values is from https://github.com/ocerman/zenpower. |
12 | * The information is not confirmed from chip datasheets, but experiments |
12 | * The information is not confirmed from chip datasheets, but experiments |
13 | * suggest that it provides reasonable temperature values. |
13 | * suggest that it provides reasonable temperature values. |
14 | */ |
14 | */ |
Line -... | Line 15... | ||
- | 15 | ||
- | 16 | /* Ported for Kolibri OS by turbocat (Maxim Logaeav). 2021 */ |
|
- | 17 | /* Thanks: dunkaist, punk_joker, doczom. */ |
|
15 | 18 | ||
16 | #include |
19 | #include |
17 | #include |
20 | #include |
18 | #include |
21 | #include |
19 | #include |
22 | #include |
Line 168... | Line 171... | ||
168 | temp = (regval >> ZEN_CUR_TEMP_SHIFT) * 125; |
171 | temp = (regval >> ZEN_CUR_TEMP_SHIFT) * 125; |
169 | if (regval & data->temp_adjust_mask) |
172 | if (regval & data->temp_adjust_mask) |
170 | temp -= 49000; |
173 | temp -= 49000; |
171 | return temp; |
174 | return temp; |
172 | } |
175 | } |
173 | 176 | #if 0 |
|
174 | const char *k10temp_temp_label[] = { |
177 | const char *k10temp_temp_label[] = { |
175 | "Tctl", |
178 | "Tctl", |
176 | "Tdie", |
179 | "Tdie", |
177 | "Tccd1", |
180 | "Tccd1", |
178 | "Tccd2", |
181 | "Tccd2", |
Line 195... | Line 198... | ||
195 | default: |
198 | default: |
196 | return -EOPNOTSUPP; |
199 | return -EOPNOTSUPP; |
197 | } |
200 | } |
198 | return 0; |
201 | return 0; |
199 | } |
202 | } |
- | 203 | #endif |
|
Line 200... | Line 204... | ||
200 | 204 | ||
201 | int k10temp_read_temp(struct device *dev, u32 attr, int channel, |
205 | int k10temp_read_temp(struct device *dev, u32 attr, int channel, |
202 | long *val) |
206 | long *val) |
203 | { |
207 | { |
Line 288... | Line 292... | ||
288 | 292 | ||
289 | data->read_htcreg(data->pdev, ®); |
293 | data->read_htcreg(data->pdev, ®); |
290 | if (!(reg & HTC_ENABLE)) |
294 | if (!(reg & HTC_ENABLE)) |
291 | return 0; |
295 | return 0; |
292 | break; |
296 | break; |
293 | case hwmon_temp_label: |
297 | // case hwmon_temp_label: |
294 | /* Show temperature labels only on Zen CPUs */ |
298 | // /* Show temperature labels only on Zen CPUs */ |
295 | if (!data->is_zen || !HAVE_TEMP(data, channel)) |
299 | // if (!data->is_zen || !HAVE_TEMP(data, channel)) |
296 | return 0; |
300 | // return 0; |
297 | break; |
301 | // break; |
298 | default: |
302 | default: |
299 | return 0; |
303 | return 0; |
300 | } |
304 | } |
301 | break; |
305 | break; |
302 | default: |
306 | default: |
303 | return 0; |
307 | return 0; |
304 | } |
308 | } |
305 | return 0444; |
309 | return 0444; |
306 | } |
310 | } |
307 | 311 | #if 0 |
|
308 | bool has_erratum_319(struct pci_dev *pdev) |
312 | bool has_erratum_319(struct pci_dev *pdev) |
309 | { |
313 | { |
Line 310... | Line 314... | ||
310 | u32 pkg_type, reg_dram_cfg; |
314 | u32 pkg_type, reg_dram_cfg; |
Line 336... | Line 340... | ||
336 | * and AM3 formats, but that's the best we can do. |
340 | * and AM3 formats, but that's the best we can do. |
337 | */ |
341 | */ |
Line 338... | Line 342... | ||
338 | 342 | ||
339 | return boot_cpu_data.x86_model < 4; |
343 | return boot_cpu_data.x86_model < 4; |
- | 344 | } |
|
Line 340... | Line 345... | ||
340 | } |
345 | #endif |
341 | 346 | ||
342 | const struct hwmon_channel_info *k10temp_info[] = { |
347 | const struct hwmon_channel_info *k10temp_info[] = { |
343 | HWMON_CHANNEL_INFO(temp, |
348 | HWMON_CHANNEL_INFO(temp, |
Line 388... | Line 393... | ||
388 | } |
393 | } |
389 | } |
394 | } |
Line 390... | Line 395... | ||
390 | 395 | ||
391 | int k10temp_probe(struct pci_dev *pdev, const struct pci_device_id *id, struct device *hwmon_dev) |
396 | int k10temp_probe(struct pci_dev *pdev, const struct pci_device_id *id, struct device *hwmon_dev) |
392 | { |
397 | { |
393 | int unreliable = has_erratum_319(pdev); |
398 | // int unreliable = has_erratum_319(pdev); |
394 | struct device *dev = &pdev->dev; |
399 | struct device *dev = &pdev->dev; |
395 | struct k10temp_data *data; |
400 | struct k10temp_data *data; |
396 | int i; |
401 | int i; |
397 | if (unreliable) { |
402 | /* if (unreliable) { |
398 | if (!force) { |
403 | if (!force) { |
399 | dev_err(dev,"unreliable CPU thermal sensor; monitoring disabled\n"); |
404 | dev_err(dev,"unreliable CPU thermal sensor; monitoring disabled\n"); |
400 | return -ENODEV; |
405 | return -ENODEV; |
401 | } |
406 | } |
402 | dev_warn(dev, |
407 | dev_warn(dev, |
403 | "unreliable CPU thermal sensor; check erratum 319\n"); |
408 | "unreliable CPU thermal sensor; check erratum 319\n"); |
- | 409 | } |
|
404 | } |
410 | */ |
405 | data = kzalloc(sizeof(struct k10temp_data), GFP_KERNEL); |
411 | data = kzalloc(sizeof(struct k10temp_data), GFP_KERNEL); |
406 | memset(data, 0x0, sizeof(struct k10temp_data)); |
412 | memset(data, 0x0, sizeof(struct k10temp_data)); |
407 | if (!data) |
413 | if (!data) |
Line 482... | Line 488... | ||
482 | { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_19H_DF_F3) }, |
488 | { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_19H_DF_F3) }, |
483 | { PCI_VDEVICE(HYGON, PCI_DEVICE_ID_AMD_17H_DF_F3) }, |
489 | { PCI_VDEVICE(HYGON, PCI_DEVICE_ID_AMD_17H_DF_F3) }, |
484 | {} |
490 | {} |
485 | }; |
491 | }; |
Line 486... | Line 492... | ||
486 | 492 | ||
487 | int __stdcall service_proc(ioctl_t *my_ctl){ |
493 | #define K10TEMP_NA (~0) |
488 | return 0; |
- | |
Line -... | Line 494... | ||
- | 494 | #define CHANEL_MAX 9 |
|
- | 495 | ||
- | 496 | #pragma pack(push, 1) |
|
- | 497 | struct{ |
|
- | 498 | int Tctl; |
|
- | 499 | int Tdie; |
|
- | 500 | int Tccd1; |
|
- | 501 | int Tccd2; |
|
- | 502 | int Tccd3; |
|
- | 503 | int Tccd4; |
|
- | 504 | int Tccd5; |
|
- | 505 | int Tccd6; |
|
- | 506 | int Tccd7; |
|
- | 507 | int Tccd8; |
|
- | 508 | ||
- | 509 | int Tmax; |
|
- | 510 | int Tcrit; |
|
- | 511 | int Tcrit_hyst; |
|
- | 512 | }k10temp_out; |
|
- | 513 | #pragma pack(pop) |
|
- | 514 | ||
489 | } |
515 | struct device k10temp_device; |
490 | 516 | ||
491 | void show_temp_info(struct device *dev, u32 attr, int channel, char* label){ |
517 | void read_temp_info(struct device *dev, u32 attr, int channel, int *val){ |
492 | long temp=0; |
518 | long temp=0; |
493 | if(k10temp_is_visible(dev->driver_data, hwmon_temp, attr, channel)){ |
519 | if(k10temp_is_visible(dev->driver_data, hwmon_temp, attr, channel)){ |
- | 520 | k10temp_read_temp(dev, attr, channel, &temp); |
|
- | 521 | *val=temp; |
|
494 | k10temp_read_temp(dev, attr, channel, &temp); |
522 | }else{ |
495 | printk("%s = %d\n",label, temp); |
523 | *val=K10TEMP_NA; |
Line -... | Line 524... | ||
- | 524 | } |
|
- | 525 | } |
|
- | 526 | ||
- | 527 | void read_all_info(struct device* dev){ |
|
- | 528 | for(int c=0; c<=CHANEL_MAX; c++){ |
|
- | 529 | read_temp_info(dev, hwmon_temp_input, c, (int*)&k10temp_out+c); |
|
- | 530 | } |
|
- | 531 | read_temp_info(dev, hwmon_temp_max, 0, &k10temp_out.Tmax); |
|
Line 496... | Line 532... | ||
496 | } |
532 | read_temp_info(dev, hwmon_temp_crit, 0, &k10temp_out.Tcrit); |
497 | } |
533 | read_temp_info(dev, hwmon_temp_crit_hyst, 0, &k10temp_out.Tcrit_hyst); |
498 | 534 | } |
|
499 | - | ||
500 | void show_all_info(struct device* dev){ |
- | |
501 | const char *hwmon_label=NULL; |
- | |
502 | int i=0; |
- | |
503 | for(i=0; i<=9; i++){ |
535 | |
504 | if(k10temp_is_visible(dev->driver_data, hwmon_temp, hwmon_temp_label, i)){ |
536 | int __stdcall service_proc(ioctl_t *my_ctl){ |
505 | k10temp_read_labels(dev, hwmon_temp, 0, i, &hwmon_label); |
537 | if(!my_ctl || !my_ctl->output){ |
506 | printk("%s:\n",hwmon_label); |
538 | return 1; |
507 | } |
539 | } |
508 | show_temp_info(dev, hwmon_temp_input, i, "temp"); |
540 | read_all_info(&k10temp_device); |
- | 541 | if(my_ctl->out_size == sizeof(k10temp_out)){ |
|
509 | show_temp_info(dev, hwmon_temp_max, i, "temp_max"); |
542 | memcpy(my_ctl->output, &k10temp_out, sizeof(k10temp_out)); |
Line -... | Line 543... | ||
- | 543 | return 0; |
|
Line 510... | Line 544... | ||
510 | show_temp_info(dev, hwmon_temp_crit, i, "temp_crit"); |
544 | } |
511 | show_temp_info(dev, hwmon_temp_crit_hyst, i, "temp_crit_hyst"); |
545 | return 1; |
512 | } |
546 | } |
513 | } |
547 | |
514 | - | ||
515 | 548 | extern void init_amd_nbs(void); |
|
516 | uint32_t drvEntry(int action, char *cmdline){ |
549 | |
517 | if(action != 1){ |
550 | uint32_t drvEntry(int action, char *cmdline){ |
Line 518... | Line 551... | ||
518 | return 0; |
551 | if(action != 1){ |
Line 519... | Line 552... | ||
519 | } |
552 | return 0; |
520 | struct device k10temp_device; |
553 | } |
521 | pci_dev_t device; |
554 | pci_dev_t device; |
522 | struct pci_device_id *k10temp_id; |
555 | const struct pci_device_id *k10temp_id; |
523 | int err; |
556 | int err; |
Line 524... | Line 557... | ||
524 | 557 | ||
Line 525... | Line 558... | ||
525 | cpu_detect(&boot_cpu_data); |
558 | cpu_detect(&boot_cpu_data); |
526 | 559 | ||
527 | err = enum_pci_devices(); |
560 | err = enum_pci_devices(); |
528 | if(unlikely(err != 0)) { |
561 | if(unlikely(err != 0)) { |
Line 529... | Line 562... | ||
529 | printk("k10temp: Device enumeration failed\n"); |
562 | printk("k10temp: Device enumeration failed!\n"); |
530 | return -1; |
- | |
531 | } |
563 | return -1; |
532 | - | ||
533 | k10temp_id = find_pci_device(&device, k10temp_id_table); |
- | |
534 | - | ||
535 | if( unlikely(k10temp_id == NULL) ){ |
- | |
536 | printk("k10temp: Device not found\n"); |
- | |
537 | return -ENODEV; |
- | |
538 | } |
- | |
539 | - | ||
540 | init_amd_nbs(); |
- | |
541 | - | ||
542 | k10temp_probe(&device.pci_dev, k10temp_id, &k10temp_device); |
- | |
543 | long temp; |
564 | } |
544 | /* if(k10temp_is_visible(k10temp_device.driver_data, hwmon_temp, hwmon_temp_input, 0)){ |
565 |