Skip to content

Commit 8a8b6bb

Browse files
ricardonrafaeljw
authored andcommitted
thermal: intel: hfi: Refactor enabling code into helper functions
In preparation for the addition of a suspend notifier, wrap the logic to enable HFI and program its memory buffer into helper functions. Both the CPU hotplug callback and the suspend notifier will use them. This refactoring does not introduce functional changes. Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent d654362 commit 8a8b6bb

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

drivers/thermal/intel/intel_hfi.c

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,26 @@ static void init_hfi_instance(struct hfi_instance *hfi_instance)
347347
hfi_instance->data = hfi_instance->hdr + hfi_features.hdr_size;
348348
}
349349

350+
/* Caller must hold hfi_instance_lock. */
351+
static void hfi_enable(void)
352+
{
353+
u64 msr_val;
354+
355+
rdmsrl(MSR_IA32_HW_FEEDBACK_CONFIG, msr_val);
356+
msr_val |= HW_FEEDBACK_CONFIG_HFI_ENABLE_BIT;
357+
wrmsrl(MSR_IA32_HW_FEEDBACK_CONFIG, msr_val);
358+
}
359+
360+
static void hfi_set_hw_table(struct hfi_instance *hfi_instance)
361+
{
362+
phys_addr_t hw_table_pa;
363+
u64 msr_val;
364+
365+
hw_table_pa = virt_to_phys(hfi_instance->hw_table);
366+
msr_val = hw_table_pa | HW_FEEDBACK_PTR_VALID_BIT;
367+
wrmsrl(MSR_IA32_HW_FEEDBACK_PTR, msr_val);
368+
}
369+
350370
/**
351371
* intel_hfi_online() - Enable HFI on @cpu
352372
* @cpu: CPU in which the HFI will be enabled
@@ -364,8 +384,6 @@ void intel_hfi_online(unsigned int cpu)
364384
{
365385
struct hfi_instance *hfi_instance;
366386
struct hfi_cpu_info *info;
367-
phys_addr_t hw_table_pa;
368-
u64 msr_val;
369387
u16 die_id;
370388

371389
/* Nothing to do if hfi_instances are missing. */
@@ -409,8 +427,6 @@ void intel_hfi_online(unsigned int cpu)
409427
if (!hfi_instance->hw_table)
410428
goto unlock;
411429

412-
hw_table_pa = virt_to_phys(hfi_instance->hw_table);
413-
414430
/*
415431
* Allocate memory to keep a local copy of the table that
416432
* hardware generates.
@@ -420,16 +436,6 @@ void intel_hfi_online(unsigned int cpu)
420436
if (!hfi_instance->local_table)
421437
goto free_hw_table;
422438

423-
/*
424-
* Program the address of the feedback table of this die/package. On
425-
* some processors, hardware remembers the old address of the HFI table
426-
* even after having been reprogrammed and re-enabled. Thus, do not free
427-
* the pages allocated for the table or reprogram the hardware with a
428-
* new base address. Namely, program the hardware only once.
429-
*/
430-
msr_val = hw_table_pa | HW_FEEDBACK_PTR_VALID_BIT;
431-
wrmsrl(MSR_IA32_HW_FEEDBACK_PTR, msr_val);
432-
433439
init_hfi_instance(hfi_instance);
434440

435441
INIT_DELAYED_WORK(&hfi_instance->update_work, hfi_update_work_fn);
@@ -438,13 +444,8 @@ void intel_hfi_online(unsigned int cpu)
438444

439445
cpumask_set_cpu(cpu, hfi_instance->cpus);
440446

441-
/*
442-
* Enable the hardware feedback interface and never disable it. See
443-
* comment on programming the address of the table.
444-
*/
445-
rdmsrl(MSR_IA32_HW_FEEDBACK_CONFIG, msr_val);
446-
msr_val |= HW_FEEDBACK_CONFIG_HFI_ENABLE_BIT;
447-
wrmsrl(MSR_IA32_HW_FEEDBACK_CONFIG, msr_val);
447+
hfi_set_hw_table(hfi_instance);
448+
hfi_enable();
448449

449450
unlock:
450451
mutex_unlock(&hfi_instance_lock);

0 commit comments

Comments
 (0)