^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * pcc-cpufreq.c - Processor Clocking Control firmware cpufreq interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2009 Red Hat, Matthew Garrett <mjg@redhat.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2009 Hewlett-Packard Development Company, L.P.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Nagananda Chumbalkar <nagananda.chumbalkar@hp.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * This program is free software; you can redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * it under the terms of the GNU General Public License as published by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * the Free Software Foundation; version 2 of the License.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * This program is distributed in the hope that it will be useful, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * WITHOUT ANY WARRANTY; without even the implied warranty of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or NON
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * INFRINGEMENT. See the GNU General Public License for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * You should have received a copy of the GNU General Public License along
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * with this program; if not, write to the Free Software Foundation, Inc.,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * 675 Mass Ave, Cambridge, MA 02139, USA.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/cpufreq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/compiler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <acpi/processor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define PCC_VERSION "1.10.00"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define POLL_LOOPS 300
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define CMD_COMPLETE 0x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define CMD_GET_FREQ 0x0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define CMD_SET_FREQ 0x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define BUF_SZ 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct pcc_register_resource {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) u8 descriptor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) u16 length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) u8 space_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) u8 bit_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) u8 bit_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) u8 access_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) u64 address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) } __attribute__ ((packed));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct pcc_memory_resource {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) u8 descriptor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) u16 length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) u8 space_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) u8 resource_usage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) u8 type_specific;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) u64 granularity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) u64 minimum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) u64 maximum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) u64 translation_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) u64 address_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) } __attribute__ ((packed));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static struct cpufreq_driver pcc_cpufreq_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) struct pcc_header {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) u32 signature;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) u16 length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) u8 major;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) u8 minor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) u32 features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) u16 command;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) u16 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) u32 latency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) u32 minimum_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) u32 maximum_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) u32 nominal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) u32 throttled_frequency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) u32 minimum_frequency;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) static void __iomem *pcch_virt_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) static struct pcc_header __iomem *pcch_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) static DEFINE_SPINLOCK(pcc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) static struct acpi_generic_address doorbell;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) static u64 doorbell_preserve;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static u64 doorbell_write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static u8 OSC_UUID[16] = {0x9F, 0x2C, 0x9B, 0x63, 0x91, 0x70, 0x1f, 0x49,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 0xBB, 0x4F, 0xA5, 0x98, 0x2F, 0xA1, 0xB5, 0x46};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct pcc_cpu {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) u32 input_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) u32 output_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static struct pcc_cpu __percpu *pcc_cpu_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static int pcc_cpufreq_verify(struct cpufreq_policy_data *policy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) cpufreq_verify_within_cpu_limits(policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static inline void pcc_cmd(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) u64 doorbell_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) acpi_read(&doorbell_value, &doorbell);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) acpi_write((doorbell_value & doorbell_preserve) | doorbell_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) &doorbell);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) for (i = 0; i < POLL_LOOPS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) if (ioread16(&pcch_hdr->status) & CMD_COMPLETE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static inline void pcc_clear_mapping(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) if (pcch_virt_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) iounmap(pcch_virt_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) pcch_virt_addr = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) static unsigned int pcc_get_freq(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct pcc_cpu *pcc_cpu_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) unsigned int curr_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) unsigned int freq_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) u16 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) u32 input_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) u32 output_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) spin_lock(&pcc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) pr_debug("get: get_freq for CPU %d\n", cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) pcc_cpu_data = per_cpu_ptr(pcc_cpu_info, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) input_buffer = 0x1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) iowrite32(input_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) (pcch_virt_addr + pcc_cpu_data->input_offset));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) iowrite16(CMD_GET_FREQ, &pcch_hdr->command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) pcc_cmd();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) output_buffer =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) ioread32(pcch_virt_addr + pcc_cpu_data->output_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) /* Clear the input buffer - we are done with the current command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) memset_io((pcch_virt_addr + pcc_cpu_data->input_offset), 0, BUF_SZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) status = ioread16(&pcch_hdr->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) if (status != CMD_COMPLETE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) pr_debug("get: FAILED: for CPU %d, status is %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) cpu, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) goto cmd_incomplete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) iowrite16(0, &pcch_hdr->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) curr_freq = (((ioread32(&pcch_hdr->nominal) * (output_buffer & 0xff))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) / 100) * 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) pr_debug("get: SUCCESS: (virtual) output_offset for cpu %d is "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) "0x%p, contains a value of: 0x%x. Speed is: %d MHz\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) cpu, (pcch_virt_addr + pcc_cpu_data->output_offset),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) output_buffer, curr_freq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) freq_limit = (output_buffer >> 8) & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) if (freq_limit != 0xff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) pr_debug("get: frequency for cpu %d is being temporarily"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) " capped at %d\n", cpu, curr_freq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) spin_unlock(&pcc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) return curr_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) cmd_incomplete:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) iowrite16(0, &pcch_hdr->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) spin_unlock(&pcc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) static int pcc_cpufreq_target(struct cpufreq_policy *policy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) unsigned int target_freq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) unsigned int relation)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) struct pcc_cpu *pcc_cpu_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) struct cpufreq_freqs freqs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) u16 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) u32 input_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) cpu = policy->cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) pcc_cpu_data = per_cpu_ptr(pcc_cpu_info, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) pr_debug("target: CPU %d should go to target freq: %d "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) "(virtual) input_offset is 0x%p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) cpu, target_freq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) (pcch_virt_addr + pcc_cpu_data->input_offset));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) freqs.old = policy->cur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) freqs.new = target_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) cpufreq_freq_transition_begin(policy, &freqs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) spin_lock(&pcc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) input_buffer = 0x1 | (((target_freq * 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) / (ioread32(&pcch_hdr->nominal) * 1000)) << 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) iowrite32(input_buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) (pcch_virt_addr + pcc_cpu_data->input_offset));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) iowrite16(CMD_SET_FREQ, &pcch_hdr->command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) pcc_cmd();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) /* Clear the input buffer - we are done with the current command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) memset_io((pcch_virt_addr + pcc_cpu_data->input_offset), 0, BUF_SZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) status = ioread16(&pcch_hdr->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) iowrite16(0, &pcch_hdr->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) cpufreq_freq_transition_end(policy, &freqs, status != CMD_COMPLETE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) spin_unlock(&pcc_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) if (status != CMD_COMPLETE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) pr_debug("target: FAILED for cpu %d, with status: 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) cpu, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) pr_debug("target: was SUCCESSFUL for cpu %d\n", cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) static int pcc_get_offset(int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) union acpi_object *pccp, *offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) struct pcc_cpu *pcc_cpu_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) struct acpi_processor *pr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) pr = per_cpu(processors, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) pcc_cpu_data = per_cpu_ptr(pcc_cpu_info, cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) if (!pr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) status = acpi_evaluate_object(pr->handle, "PCCP", NULL, &buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) if (ACPI_FAILURE(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) pccp = buffer.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) if (!pccp || pccp->type != ACPI_TYPE_PACKAGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) offset = &(pccp->package.elements[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) if (!offset || offset->type != ACPI_TYPE_INTEGER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) pcc_cpu_data->input_offset = offset->integer.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) offset = &(pccp->package.elements[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) if (!offset || offset->type != ACPI_TYPE_INTEGER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) pcc_cpu_data->output_offset = offset->integer.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) memset_io((pcch_virt_addr + pcc_cpu_data->input_offset), 0, BUF_SZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) memset_io((pcch_virt_addr + pcc_cpu_data->output_offset), 0, BUF_SZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) pr_debug("pcc_get_offset: for CPU %d: pcc_cpu_data "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) "input_offset: 0x%x, pcc_cpu_data output_offset: 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) cpu, pcc_cpu_data->input_offset, pcc_cpu_data->output_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) kfree(buffer.pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) static int __init pcc_cpufreq_do_osc(acpi_handle *handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) struct acpi_object_list input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) union acpi_object in_params[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) union acpi_object *out_obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) u32 capabilities[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) u32 errors;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) u32 supported;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) input.count = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) input.pointer = in_params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) in_params[0].type = ACPI_TYPE_BUFFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) in_params[0].buffer.length = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) in_params[0].buffer.pointer = OSC_UUID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) in_params[1].type = ACPI_TYPE_INTEGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) in_params[1].integer.value = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) in_params[2].type = ACPI_TYPE_INTEGER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) in_params[2].integer.value = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) in_params[3].type = ACPI_TYPE_BUFFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) in_params[3].buffer.length = 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) in_params[3].buffer.pointer = (u8 *)&capabilities;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) capabilities[0] = OSC_QUERY_ENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) capabilities[1] = 0x1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) status = acpi_evaluate_object(*handle, "_OSC", &input, &output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) if (ACPI_FAILURE(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) if (!output.length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) out_obj = output.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) if (out_obj->type != ACPI_TYPE_BUFFER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) if (errors) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) supported = *((u32 *)(out_obj->buffer.pointer + 4));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) if (!(supported & 0x1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) kfree(output.pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) capabilities[0] = 0x0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) capabilities[1] = 0x1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) status = acpi_evaluate_object(*handle, "_OSC", &input, &output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) if (ACPI_FAILURE(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) if (!output.length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) out_obj = output.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) if (out_obj->type != ACPI_TYPE_BUFFER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) if (errors) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) supported = *((u32 *)(out_obj->buffer.pointer + 4));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) if (!(supported & 0x1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) kfree(output.pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) static int __init pcc_cpufreq_probe(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) struct pcc_memory_resource *mem_resource;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) struct pcc_register_resource *reg_resource;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) union acpi_object *out_obj, *member;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) acpi_handle handle, osc_handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) status = acpi_get_handle(NULL, "\\_SB", &handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) if (ACPI_FAILURE(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) if (!acpi_has_method(handle, "PCCH"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) status = acpi_get_handle(handle, "_OSC", &osc_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) if (ACPI_SUCCESS(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) ret = pcc_cpufreq_do_osc(&osc_handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) pr_debug("probe: _OSC evaluation did not succeed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) /* Firmware's use of _OSC is optional */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) status = acpi_evaluate_object(handle, "PCCH", NULL, &output);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) if (ACPI_FAILURE(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) out_obj = output.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) if (out_obj->type != ACPI_TYPE_PACKAGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) member = &out_obj->package.elements[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) if (member->type != ACPI_TYPE_BUFFER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) mem_resource = (struct pcc_memory_resource *)member->buffer.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) pr_debug("probe: mem_resource descriptor: 0x%x,"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) " length: %d, space_id: %d, resource_usage: %d,"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) " type_specific: %d, granularity: 0x%llx,"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) " minimum: 0x%llx, maximum: 0x%llx,"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) " translation_offset: 0x%llx, address_length: 0x%llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) mem_resource->descriptor, mem_resource->length,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) mem_resource->space_id, mem_resource->resource_usage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) mem_resource->type_specific, mem_resource->granularity,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) mem_resource->minimum, mem_resource->maximum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) mem_resource->translation_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) mem_resource->address_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) if (mem_resource->space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) pcch_virt_addr = ioremap(mem_resource->minimum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) mem_resource->address_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) if (pcch_virt_addr == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) pr_debug("probe: could not map shared mem region\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) pcch_hdr = pcch_virt_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) pr_debug("probe: PCCH header (virtual) addr: 0x%p\n", pcch_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) pr_debug("probe: PCCH header is at physical address: 0x%llx,"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) " signature: 0x%x, length: %d bytes, major: %d, minor: %d,"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) " supported features: 0x%x, command field: 0x%x,"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) " status field: 0x%x, nominal latency: %d us\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) mem_resource->minimum, ioread32(&pcch_hdr->signature),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) ioread16(&pcch_hdr->length), ioread8(&pcch_hdr->major),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) ioread8(&pcch_hdr->minor), ioread32(&pcch_hdr->features),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) ioread16(&pcch_hdr->command), ioread16(&pcch_hdr->status),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) ioread32(&pcch_hdr->latency));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) pr_debug("probe: min time between commands: %d us,"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) " max time between commands: %d us,"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) " nominal CPU frequency: %d MHz,"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) " minimum CPU frequency: %d MHz,"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) " minimum CPU frequency without throttling: %d MHz\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) ioread32(&pcch_hdr->minimum_time),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) ioread32(&pcch_hdr->maximum_time),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) ioread32(&pcch_hdr->nominal),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) ioread32(&pcch_hdr->throttled_frequency),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) ioread32(&pcch_hdr->minimum_frequency));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) member = &out_obj->package.elements[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) if (member->type != ACPI_TYPE_BUFFER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) goto pcch_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) reg_resource = (struct pcc_register_resource *)member->buffer.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) doorbell.space_id = reg_resource->space_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) doorbell.bit_width = reg_resource->bit_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) doorbell.bit_offset = reg_resource->bit_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) doorbell.access_width = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) doorbell.address = reg_resource->address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) pr_debug("probe: doorbell: space_id is %d, bit_width is %d, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) "bit_offset is %d, access_width is %d, address is 0x%llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) doorbell.space_id, doorbell.bit_width, doorbell.bit_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) doorbell.access_width, reg_resource->address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) member = &out_obj->package.elements[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) if (member->type != ACPI_TYPE_INTEGER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) goto pcch_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) doorbell_preserve = member->integer.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) member = &out_obj->package.elements[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) if (member->type != ACPI_TYPE_INTEGER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) goto pcch_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) doorbell_write = member->integer.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) pr_debug("probe: doorbell_preserve: 0x%llx,"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) " doorbell_write: 0x%llx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) doorbell_preserve, doorbell_write);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) pcc_cpu_info = alloc_percpu(struct pcc_cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) if (!pcc_cpu_info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) goto pcch_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) printk(KERN_DEBUG "pcc-cpufreq: (v%s) driver loaded with frequency"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) " limits: %d MHz, %d MHz\n", PCC_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) ioread32(&pcch_hdr->minimum_frequency),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) ioread32(&pcch_hdr->nominal));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) kfree(output.pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) pcch_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) pcc_clear_mapping();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) kfree(output.pointer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) static int pcc_cpufreq_cpu_init(struct cpufreq_policy *policy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) unsigned int cpu = policy->cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) unsigned int result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) if (!pcch_virt_addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) result = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) result = pcc_get_offset(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) pr_debug("init: PCCP evaluation failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) policy->max = policy->cpuinfo.max_freq =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) ioread32(&pcch_hdr->nominal) * 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) policy->min = policy->cpuinfo.min_freq =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) ioread32(&pcch_hdr->minimum_frequency) * 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) pr_debug("init: policy->max is %d, policy->min is %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) policy->max, policy->min);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) static int pcc_cpufreq_cpu_exit(struct cpufreq_policy *policy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) static struct cpufreq_driver pcc_cpufreq_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) .flags = CPUFREQ_CONST_LOOPS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) .get = pcc_get_freq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) .verify = pcc_cpufreq_verify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) .target = pcc_cpufreq_target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) .init = pcc_cpufreq_cpu_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) .exit = pcc_cpufreq_cpu_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) .name = "pcc-cpufreq",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) static int __init pcc_cpufreq_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) /* Skip initialization if another cpufreq driver is there. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) if (cpufreq_get_current_driver())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) return -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) if (acpi_disabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) ret = pcc_cpufreq_probe();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) pr_debug("pcc_cpufreq_init: PCCH evaluation failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) if (num_present_cpus() > 4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) pcc_cpufreq_driver.flags |= CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) pr_err("%s: Too many CPUs, dynamic performance scaling disabled\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) pr_err("%s: Try to enable another scaling driver through BIOS settings\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) pr_err("%s: and complain to the system vendor\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) ret = cpufreq_register_driver(&pcc_cpufreq_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) static void __exit pcc_cpufreq_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) cpufreq_unregister_driver(&pcc_cpufreq_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) pcc_clear_mapping();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) free_percpu(pcc_cpu_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) static const struct acpi_device_id __maybe_unused processor_device_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) {ACPI_PROCESSOR_OBJECT_HID, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) {ACPI_PROCESSOR_DEVICE_HID, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) MODULE_DEVICE_TABLE(acpi, processor_device_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) MODULE_AUTHOR("Matthew Garrett, Naga Chumbalkar");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) MODULE_VERSION(PCC_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) MODULE_DESCRIPTION("Processor Clocking Control interface driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) late_initcall(pcc_cpufreq_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) module_exit(pcc_cpufreq_exit);