<commit_before>/*
 * Intel SpeedStep SMI driver.
 *
 * (C) 2003  <NAME> <<EMAIL>>
 *
 *  Licensed under the terms of the GNU GPL License version 2.
 *
 */


/*********************************************************************
 *                        SPEEDSTEP - DEFINITIONS                    *
 *********************************************************************/

#include <linux/kernel.h>
#include <linux/module.h> 
#include <linux/moduleparam.h> 
#include <linux/init.h>
#include <linux/cpufreq.h>
#include <linux/pci.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <asm/ist.h>

#include "speedstep-lib.h"

/* speedstep system management interface port/command.
 *
 * These parameters are got from IST-SMI BIOS call.
 * If user gives it, these are used.
 * 
 */
static int		smi_port	= 0;
static int		smi_cmd		= 0;
static unsigned int	smi_sig		= 0;

/* info about the processor */
static unsigned int	speedstep_processor = 0;

/* 
 *   There are only two frequency states for each processor. Values
 * are in kHz for the time being.
 */
static struct cpufreq_frequency_table speedstep_freqs[] = {
	{SPEEDSTEP_HIGH, 	0},
	{SPEEDSTEP_LOW,		0},
	{0,			CPUFREQ_TABLE_END},
};

#define GET_SPEEDSTEP_OWNER 0
#define GET_SPEEDSTEP_STATE 1
#define SET_SPEEDSTEP_STATE 2
#define GET_SPEEDSTEP_FREQS 4

/* how often shall the SMI call be tried if it failed, e.g. because
 * of DMA activity going on? */
#define SMI_TRIES 5

#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "speedstep-smi", msg)

/**
 * speedstep_smi_ownership
 */
static int speedstep_smi_ownership (void)
{
	u32 command, result, magic;
	u32 function = GET_SPEEDSTEP_OWNER;
	unsigned char magic_data[] = "Copyright (c) 1999 Intel Corporation";

	command = (smi_sig & 0xffffff00) | (smi_cmd & 0xff);
	magic = virt_to_phys(magic_data);

	dprintk("trying to obtain ownership with command %x at port %x\n", command, smi_port);

	__asm__ __volatile__(
		"out %%al, (%%dx)\n"
		: "=D" (result)
		: "a" (command), "b" (function), "c" (0), "d" (smi_port), "D" (0), "S" (magic)
	);

	dprintk("result is %x\n", result);

	return result;
}

/**
 * speedstep_smi_get_freqs - get SpeedStep preferred & current freq.
 * @low: the low frequency value is placed here
 * @high: the high frequency value is placed here<commit_msg>[PATCH] cpufreq: speedstep-smi asm fix<commit_after>/*
 * Intel SpeedStep SMI driver.
 *
 * (C) 2003  <NAME> <<EMAIL>>
 *
 *  Licensed under the terms of the GNU GPL License version 2.
 *
 */


/*********************************************************************
 *                        SPEEDSTEP - DEFINITIONS                    *
 *********************************************************************/

#include <linux/kernel.h>
#include <linux/module.h> 
#include <linux/moduleparam.h> 
#include <linux/init.h>
#include <linux/cpufreq.h>
#include <linux/pci.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <asm/ist.h>

#include "speedstep-lib.h"

/* speedstep system management interface port/command.
 *
 * These parameters are got from IST-SMI BIOS call.
 * If user gives it, these are used.
 * 
 */
static int		smi_port	= 0;
static int		smi_cmd		= 0;
static unsigned int	smi_sig		= 0;

/* info about the processor */
static unsigned int	speedstep_processor = 0;

/* 
 *   There are only two frequency states for each processor. Values
 * are in kHz for the time being.
 */
static struct cpufreq_frequency_table speedstep_freqs[] = {
	{SPEEDSTEP_HIGH, 	0},
	{SPEEDSTEP_LOW,		0},
	{0,			CPUFREQ_TABLE_END},
};

#define GET_SPEEDSTEP_OWNER 0
#define GET_SPEEDSTEP_STATE 1
#define SET_SPEEDSTEP_STATE 2
#define GET_SPEEDSTEP_FREQS 4

/* how often shall the SMI call be tried if it failed, e.g. because
 * of DMA activity going on? */
#define SMI_TRIES 5

#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "speedstep-smi", msg)

/**
 * speedstep_smi_ownership
 */
static int speedstep_smi_ownership (void)
{
	u32 command, result, magic;
	u32 function = GET_SPEEDSTEP_OWNER;
	unsigned char magic_data[] = "Copyright (c) 1999 Intel Corporation";

	command = (smi_sig & 0xffffff00) | (smi_cmd & 0xff);
	magic = virt_to_phys(magic_data);

	dprintk("trying to obtain ownership with command %x at port %x\n", command, smi_port);

	__asm__ __volatile__(
		"out %%al, (%%dx)\n"
		: "=D" (result)
		: "a" (command), "b" (function), "c" (0), "d" (smi_port),
			"D" (0), "S" (magic)
		: "memory"
	);

	dprintk("result is %x\n", result);

	return result;
}

/**
 * speedstep_smi_get_freqs - get SpeedStep preferred & current freq.
 * @low: the low frequency value is placed here
 * @high: the high frequency value is placed here
{'fraction_non_alphanumeric': 0.17828792104698563, 'fraction_numerical': 0.013301866552242008, 'mean_word_length': 3.975453575240128, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7140231', 'n_tokens_mistral': 1737, 'n_tokens_neox': 1626, 'n_words': 474}