summaryrefslogtreecommitdiffstats
path: root/kernel/drivers/cpufreq/sh-cpufreq.c
blob: 86628e22b2a36827d37f35d552f0624bc9dc387c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*
 * cpufreq driver for the SuperH processors.
 *
 * Copyright (C) 2002 - 2012 Paul Mundt
 * Copyright (C) 2002 M. R. Brown
 *
 * Clock framework bits from arch/avr32/mach-at32ap/cpufreq.c
 *
 *   Copyright (C) 2004-2007 Atmel Corporation
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 */
#define pr_fmt(fmt) "cpufreq: " fmt

#include <linux/types.h>
#include <linux/cpufreq.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/err.h>
#include <linux/cpumask.h>
#include <linux/cpu.h>
#include <linux/smp.h>
#include <linux/sched.h>	/* set_cpus_allowed() */
#include <linux/clk.h>
#include <linux/percpu.h>
#include <linux/sh_clk.h>

static DEFINE_PER_CPU(struct clk, sh_cpuclk);

static unsigned int sh_cpufreq_get(unsigned int cpu)
{
	return (clk_get_rate(&per_cpu(sh_cpuclk, cpu)) + 500) / 1000;
}

/*
 * Here we notify other drivers of the proposed change and the final change.
 */
static int sh_cpufreq_target(struct cpufreq_policy *policy,
			     unsigned int target_freq,
			     unsigned int relation)
{
	unsigned int cpu = policy->cpu;
	struct clk *cpuclk = &per_cpu(sh_cpuclk, cpu);
	cpumask_t cpus_allowed;
	struct cpufreq_freqs freqs;
	struct device *dev;
	long freq;

	cpus_allowed = current->cpus_allowed;
	set_cpus_allowed_ptr(current, cpumask_of(cpu));

	BUG_ON(smp_processor_id() != cpu);

	dev = get_cpu_device(cpu);

	/* Convert target_freq from kHz to Hz */
	freq = clk_round_rate(cpuclk, target_freq * 1000);

	if (freq < (policy->min * 1000) || freq > (policy->max * 1000))
		return -EINVAL;

	dev_dbg(dev, "requested frequency %u Hz\n", target_freq * 1000);

	freqs.old	= sh_cpufreq_get(cpu);
	freqs.new	= (freq + 500) / 1000;
	freqs.flags	= 0;

	cpufreq_freq_transition_begin(policy, &freqs);
	set_cpus_allowed_ptr(current, &cpus_allowed);
	clk_set_rate(cpuclk, freq);
	cpufreq_freq_transition_end(policy, &freqs, 0);

	dev_dbg(dev, "set frequency %lu Hz\n", freq);

	return 0;
}

static int sh_cpufreq_verify(struct cpufreq_policy *policy)
{
	struct clk *cpuclk = &per_cpu(sh_cpuclk, policy->cpu);
	struct cpufreq_frequency_table *freq_table;

	freq_table = cpuclk->nr_freqs ? cpuclk->freq_table : NULL;
	if (freq_table)
		return cpufreq_frequency_table_verify(policy, freq_table);

	cpufreq_verify_within_cpu_limits(policy);

	policy->min = (clk_round_rate(cpuclk, 1) + 500) / 1000;
	policy->max = (clk_round_rate(cpuclk, ~0UL) + 500) / 1000;

	cpufreq_verify_within_cpu_limits(policy);
	return 0;
}

static int sh_cpufreq_cpu_init(struct cpufreq_policy *policy)
{
	unsigned int cpu = policy->cpu;
	struct clk *cpuclk = &per_cpu(sh_cpuclk, cpu);
	struct cpufreq_frequency_table *freq_table;
	struct device *dev;

	dev = get_cpu_device(cpu);

	cpuclk = clk_get(dev, "cpu_clk");
	if (IS_ERR(cpuclk)) {
		dev_err(dev, "couldn't get CPU clk\n");
		return PTR_ERR(cpuclk);
	}

	freq_table = cpuclk->nr_freqs ? cpuclk->freq_table : NULL;
	if (freq_table) {
		int result;

		result = cpufreq_table_validate_and_show(policy, freq_table);
		if (result)
			return result;
	} else {
		dev_notice(dev, "no frequency table found, falling back "
			   "to rate rounding.\n");

		policy->min = policy->cpuinfo.min_freq =
			(clk_round_rate(cpuclk, 1) + 500) / 1000;
		policy->max = policy->cpuinfo.max_freq =
			(clk_round_rate(cpuclk, ~0UL) + 500) / 1000;
	}

	policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;

	dev_info(dev, "CPU Frequencies - Minimum %u.%03u MHz, "
	       "Maximum %u.%03u MHz.\n",
	       policy->min / 1000, policy->min % 1000,
	       policy->max / 1000, policy->max % 1000);

	return 0;
}

static int sh_cpufreq_cpu_exit(struct cpufreq_policy *policy)
{
	unsigned int cpu = policy->cpu;
	struct clk *cpuclk = &per_cpu(sh_cpuclk, cpu);

	clk_put(cpuclk);

	return 0;
}

static struct cpufreq_driver sh_cpufreq_driver = {
	.name		= "sh",
	.get		= sh_cpufreq_get,
	.target		= sh_cpufreq_target,
	.verify		= sh_cpufreq_verify,
	.init		= sh_cpufreq_cpu_init,
	.exit		= sh_cpufreq_cpu_exit,
	.attr		= cpufreq_generic_attr,
};

static int __init sh_cpufreq_module_init(void)
{
	pr_notice("SuperH CPU frequency driver.\n");
	return cpufreq_register_driver(&sh_cpufreq_driver);
}

static void __exit sh_cpufreq_module_exit(void)
{
	cpufreq_unregister_driver(&sh_cpufreq_driver);
}

module_init(sh_cpufreq_module_init);
module_exit(sh_cpufreq_module_exit);

MODULE_AUTHOR("Paul Mundt <lethal@linux-sh.org>");
MODULE_DESCRIPTION("cpufreq driver for SuperH");
MODULE_LICENSE("GPL");
tr -d '_-')" $(BUILD_DIR)/opnfv-apex-common.tar.gz: pushd ../ && git archive --format=tar.gz --prefix=opnfv-apex-common-$(RPMVERS)/ HEAD > $(BUILD_DIR)/opnfv-apex-common.tar.gz .PHONY: common-rpm-check common-rpm-check: $(BUILD_DIR)/opnfv-apex-common.tar.gz rpmbuild --clean -bi -bl rpm_specs/opnfv-apex-common.spec $(RPM_DIR_ARGS) -D "release $(shell echo $(RELEASE) | tr -d '_-')" .PHONY: common-rpm common-rpm: $(BUILD_DIR)/opnfv-apex-common.tar.gz $(RPMCOM) $(RPMCOM): @echo "Building the Apex Common RPM" # build the common RPM rpmbuild --clean -ba rpm_specs/opnfv-apex-common.spec $(RPM_DIR_ARGS) -D "release $(shell echo $(RELEASE) | tr -d '_-')" ################## # PYTHON TESTS # ################## .PHONY: python-tests python-tests: # clean previous coverage data rm -rf ../tests/.coverage rm -rf ../tests/htmlcov # run nose tests cd ../tests && PYTHONPATH=../lib/python/ nosetests-3.4 . --with-coverage --cover-package apex --cover-package apex_python_utils --cover-html --cover-min-percentage 90 # generate reports cd ../tests && coverage3 report --include '*lib/python/*' -m ####################### # PYTHON PEP8 CHECK # ####################### .PHONY: python-pep8-check python-pep8-check: pep8 ../lib/python pep8 ../tests ############### # TACKER # ############### $(BUILD_DIR)/openstack-tacker.tar.gz: @echo "Preparing the Tacker RPM prerequisites" git clone $(TACKER_REPO) -b $(TACKER_BRANCH) $(BUILD_DIR)/openstack-tacker-2016.2 cp rpm_specs/openstack-tacker-server.service $(BUILD_DIR)/openstack-tacker-2016.2 tar czf $(BUILD_DIR)/openstack-tacker.tar.gz -C $(BUILD_DIR) openstack-tacker-2016.2 .PHONY: tacker-rpm tacker-rpm: $(BUILD_DIR)/openstack-tacker.tar.gz $(BUILD_DIR)/noarch/openstack-tacker-2016.2-1.git$(TACKER_COMMIT).noarch.rpm $(BUILD_DIR)/noarch/openstack-tacker-2016.2-1.git$(TACKER_COMMIT).noarch.rpm: @echo "Building the Tacker RPM" rpmbuild --clean -ba --target noarch rpm_specs/openstack-tacker.spec $(RPM_DIR_ARGS) -D 'git .git$(TACKER_COMMIT)' ################# # TACKERCLIENT # ################# $(BUILD_DIR)/python-tackerclient.tar.gz: @echo "Preparing the TackerClient RPM prerequisites" git clone $(TACKERCLIENT_REPO) -b $(TACKERCLIENT_BRANCH) $(BUILD_DIR)/python-tackerclient-2016.2 tar czf $(BUILD_DIR)/python-tackerclient.tar.gz -C $(BUILD_DIR) python-tackerclient-2016.2 .PHONY: tackerclient-rpm tackerclient-rpm: $(BUILD_DIR)/python-tackerclient.tar.gz $(BUILD_DIR)/noarch/python-tackerclient-2016.2-1.git$(TACKERCLIENT_COMMIT).noarch.rpm $(BUILD_DIR)/noarch/python-tackerclient-2016.2-1.git$(TACKERCLIENT_COMMIT).noarch.rpm: @echo "Building the TackerClient RPM" rpmbuild --clean -ba --target noarch rpm_specs/python-tackerclient.spec $(RPM_DIR_ARGS) -D 'git .git$(TACKERCLIENT_COMMIT)' ############### # CONGRESS # ############### .PHONY: congress-clean congress-clean: @rm -rf $(BUILD_DIR)/openstack-congress-2016.2 @rm -f $(BUILD_DIR)/openstack-congress.tar.gz $(BUILD_DIR)/openstack-congress.tar.gz: @echo "Preparing the Congress RPM prerequisites" git clone $(CONGRESS_REPO) -b $(CONGRESS_BRANCH) $(BUILD_DIR)/openstack-congress-2016.2 cp rpm_specs/openstack-congress-server.service $(BUILD_DIR)/openstack-congress-2016.2 tar czf $(BUILD_DIR)/openstack-congress.tar.gz -C $(BUILD_DIR) openstack-congress-2016.2 .PHONY: congress-rpm congress-rpm: $(BUILD_DIR)/noarch/openstack-congress-2016.2-1.git$(CONGRESS_COMMIT).noarch.rpm $(BUILD_DIR)/noarch/openstack-congress-2016.2-1.git$(CONGRESS_COMMIT).noarch.rpm: $(BUILD_DIR)/openstack-congress.tar.gz @echo "Building the Congress RPM" rpmbuild --clean -ba --target noarch rpm_specs/openstack-congress.spec $(RPM_DIR_ARGS) -D 'git .git$(CONGRESS_COMMIT)' ################## # NETWORKING-VPP # ################## $(BUILD_DIR)/python-networking-vpp.tar.gz: @echo "Preparing the networking-vpp RPM prerequisites" git clone $(NETVPP_REPO) $(BUILD_DIR)/python-networking-vpp-$(NETVPP_VERS) tar czf $(BUILD_DIR)/python-networking-vpp.tar.gz -C $(BUILD_DIR) python-networking-vpp-$(NETVPP_VERS) .PHONY: networking-vpp-rpm networking-vpp-rpm: $(BUILD_DIR)/noarch/python-networking-vpp-$(NETVPP_VERS)-1.git$(NETVPP_COMMIT)$(RPM_DIST).noarch.rpm $(BUILD_DIR)/noarch/python-networking-vpp-$(NETVPP_VERS)-1.git$(NETVPP_COMMIT)$(RPM_DIST).noarch.rpm: $(BUILD_DIR)/python-networking-vpp.tar.gz @echo "Building the Networking VPP RPM" rpmbuild --clean -ba --target noarch rpm_specs/networking-vpp.spec $(RPM_DIR_ARGS) -D 'git .git$(NETVPP_COMMIT)' ############### # UNDERCLOUD # ############### .PHONY: undercloud undercloud: $(BUILD_DIR)/undercloud.qcow2 $(BUILD_DIR)/undercloud.qcow2: tackerclient-rpm @echo "Building the Apex Undercloud Image" @./undercloud.sh $(BUILD_DIR)/opnfv-apex-undercloud.tar.gz: $(BUILD_DIR)/undercloud.qcow2 @echo "Preparing the Apex Undercloud RPM prerequisites" pushd ../ && git archive --format=tar --prefix=opnfv-apex-undercloud-$(RPMVERS)/ HEAD > $(BUILD_DIR)/opnfv-apex-undercloud.tar tar -rf $(BUILD_DIR)/opnfv-apex-undercloud.tar \ --xform="s:.*undercloud.qcow2:opnfv-apex-undercloud-$(RPMVERS)/build/undercloud.qcow2:" $(BUILD_DIR)/undercloud.qcow2 gzip -f $(BUILD_DIR)/opnfv-apex-undercloud.tar .PHONY: undercloud-rpm-check undercloud-rpm-check: $(BUILD_DIR)/opnfv-apex-undercloud.tar.gz rpmbuild --clean -bi -bl rpm_specs/opnfv-apex-undercloud.spec $(RPM_DIR_ARGS) -D "release $(shell echo $(RELEASE) | tr -d '_-')" .PHONY: undercloud-rpm undercloud-rpm: $(BUILD_DIR)/opnfv-apex-undercloud.tar.gz $(RPMUDR) $(RPMUDR): @echo "Building the Apex Undercloud RPM" rpmbuild --clean -ba rpm_specs/opnfv-apex-undercloud.spec $(RPM_DIR_ARGS) -D "release $(shell echo $(RELEASE) | tr -d '_-')" ############### # OVERCLOUD # ############### .PHONY: overcloud-full overcloud-full: $(BUILD_DIR)/overcloud-full.qcow2 $(BUILD_DIR)/overcloud-full.qcow2: congress-rpm tacker-rpm networking-vpp-rpm @echo "Building the Apex Base Overcloud Image" @./overcloud-full.sh ############### # ODL # ############### .PHONY: overcloud-opendaylight overcloud-opendaylight: quagga-zrpc $(BUILD_DIR)/overcloud-full-opendaylight.qcow2 $(BUILD_DIR)/overcloud-full-opendaylight.qcow2: $(BUILD_DIR)/overcloud-full.qcow2 @echo "Building the Apex OpenDaylight Overcloud Image" @./overcloud-opendaylight.sh $(BUILD_DIR)/opnfv-apex.tar.gz: $(BUILD_DIR)/overcloud-full-opendaylight.qcow2 tar -czf $(BUILD_DIR)/opnfv-apex.tar.gz --xform="s:.*overcloud-full-opendaylight.qcow2:opnfv-apex-$(RPMVERS)/build/overcloud-full-opendaylight.qcow2:" $(BUILD_DIR)/overcloud-full-opendaylight.qcow2 .PHONY: opendaylight-rpm-check opendaylight-rpm-check: $(BUILD_DIR)/opnfv-apex.tar.gz rpmbuild --clean -bi -bl rpm_specs/opnfv-apex.spec $(RPM_DIR_ARGS) -D "release $(shell echo $(RELEASE) | tr -d '_-')" .PHONY: opendaylight-rpm opendaylight-rpm: $(BUILD_DIR)/opnfv-apex.tar.gz $(RPMODL) $(RPMODL): @echo "Building the Apex OpenDaylight RPM" # build the overcloud RPM rpmbuild --clean -ba rpm_specs/opnfv-apex.spec $(RPM_DIR_ARGS) -D "release $(shell echo $(RELEASE) | tr -d '_-')" ############### # ONOS # ############### .PHONY: overcloud-onos overcloud-onos: $(BUILD_DIR)/overcloud-full-onos.qcow2 $(BUILD_DIR)/overcloud-full-onos.qcow2: $(BUILD_DIR)/overcloud-full.qcow2 @echo "Building the Apex ONOS Overcloud Image" @./overcloud-onos.sh $(BUILD_DIR)/opnfv-apex-onos.tar.gz: $(BUILD_DIR)/overcloud-full-onos.qcow2 tar -czf $(BUILD_DIR)/opnfv-apex-onos.tar.gz --xform="s:.*overcloud-full-onos.qcow2:opnfv-apex-onos-$(RPMVERS)/build/overcloud-full-onos.qcow2:" $(BUILD_DIR)/overcloud-full-onos.qcow2 .PHONY: onos-rpm-check onos-rpm-check: $(BUILD_DIR)/opnfv-apex-onos.tar.gz rpmbuild --clean -bi -bl rpm_specs/opnfv-apex-onos.spec $(RPM_DIR_ARGS) -D "release $(shell echo $(RELEASE) | tr -d '_-')" .PHONY: onos-rpm onos-rpm: $(BUILD_DIR)/opnfv-apex-onos.tar.gz $(RPMONO) $(RPMONO): @echo "Building the Apex ONOS RPM" # build the overcloud RPM rpmbuild --clean -ba rpm_specs/opnfv-apex-onos.spec $(RPM_DIR_ARGS) -D "release $(shell echo $(RELEASE) | tr -d '_-')" ############### # ISO # ############### $(CENTISO): curl $(CENTDNLD) -z $(CENTISO) -o $(CENTISO) --verbose --silent --location iso-clean: @rm -Rf $(BUILD_DIR)/centos @rm -Rf $(BUILD_DIR)/release @rm -f $(ISO) .PHONY: mount-centiso umount-centiso mount-centiso: $(CENTISO) @echo "Mounting CentOS ISO in $(CENTDIR)" @mkdir -p $(CENTDIR) @fuseiso $(CENTISO) $(CENTDIR) umount-centiso: @set +e @echo "Unmounting CentOS ISO from $(CENTDIR)" @fusermount -u $(CENTDIR) @rmdir $(CENTDIR) @set -e .PHONY: iso iso: iso-clean images rpms $(CENTISO) @echo "Building the Apex ISO" @mkdir $(BUILD_DIR)/centos $(BUILD_DIR)/release cd $(BUILD_DIR)/centos && bsdtar -xf ../$(shell basename $(CENTISO)) # modify the installer iso's contents @chmod -R u+w $(BUILD_DIR)/centos @cp -f isolinux.cfg $(BUILD_DIR)/centos/isolinux/isolinux.cfg @ln $(RPMCOM) $(BUILD_DIR)/centos/Packages @ln $(RPMUDR) $(BUILD_DIR)/centos/Packages @ln $(RPMODL) $(BUILD_DIR)/centos/Packages @ln $(RPMONO) $(BUILD_DIR)/centos/Packages # add packages to the centos packages cd $(BUILD_DIR)/centos/Packages && yumdownloader openvswitch openstack-tripleo jq python34 python34-libs python34-yaml python34-setuptools ipxe-roms-qemu cd $(BUILD_DIR)/centos/Packages && curl -O https://radez.fedorapeople.org/python34-markupsafe-0.23-9.el7.centos.x86_64.rpm cd $(BUILD_DIR)/centos/Packages && curl -O https://radez.fedorapeople.org/python3-jinja2-2.8-5.el7.centos.noarch.rpm cd $(BUILD_DIR)/centos/Packages && curl -O http://artifacts.opnfv.org/apex/dependencies/python3-ipmi-0.3.0-1.noarch.rpm # regenerate yum repo data @echo "Generating new yum metadata" createrepo --update -g $(BUILD_ROOT)/c7-opnfv-x86_64-comps.xml $(BUILD_DIR)/centos # build the iso @echo "Building OPNFV iso" mkisofs -b isolinux/isolinux.bin -no-emul-boot -boot-load-size 4 -boot-info-table -V "OPNFV CentOS 7 x86_64" -R -J -v -T -o $(ISO) $(BUILD_DIR)/centos isohybrid $(ISO) @printf "\n\nISO is built at $(ISO)\n\n" #################### # python3-jinja2 # #################### .PHONY: python3-jinja2 python3-jinja2: python3-markupsafe cd $(BUILD_DIR) \ && curl -O -L artifacts.opnfv.org/apex/dependencies/python-jinja2-2.8-5.fc24.src.rpm \ && rpm2cpio python-jinja2-2.8-5.fc24.src.rpm | cpio -idmv \ && sed -i 's/python3-devel/python34-devel/' python-jinja2.spec \ && sed -i 's/python3-setuptools/python34-setuptools/' python-jinja2.spec \ && sed -i 's/python3-pytest/python34-pytest/' python-jinja2.spec \ && sed -i 's/python3-markupsafe/python34-markupsafe/' python-jinja2.spec \ && rpmbuild -ba python-jinja2.spec $(RPM_DIR_ARGS) -D "with_python3 1" ######################## # python3-markupsafe # ######################## .PHONY: python3-markupsafe python3-markupsafe: cd $(BUILD_DIR) \ && curl -O -L artifacts.opnfv.org/apex/dependencies/python-markupsafe-0.23-9.fc24.src.rpm \ && rpm2cpio python-markupsafe-0.23-9.fc24.src.rpm | cpio -idmv \ && sed -i 's/python3-devel/python34-devel/' python-markupsafe.spec \ && sed -i 's/python3-setuptools/python34-setuptools/' python-markupsafe.spec \ && sed -i 's/python3-pytest/python34-pytest/' python-markupsafe.spec \ && sed -i 's/python3-markupsafe/python34-markupsafe/' python-markupsafe.spec \ && rpmbuild -ba python-markupsafe.spec $(RPM_DIR_ARGS) -D "with_python3 1" ################## # Quagga Clean # ################## .PHONY: quagga-clean quagga-clean: @rm -rf $(QUAGGA_BUILD_DIR) @sudo yum -y remove zrpc* quagga* c-capnproto* thrift* ################# # Quagga+ZRPC # ################# .PHONY: quagga-zrpc quagga-zrpc: quagga-clean thrift-rpm capnproto-rpm quagga-rpm zrpc-rpm ########## # ZRPC # ########## .PHONY: zrpc-rpm zrpc-rpm: quagga-rpm $(QUAGGA_RPMS_DIR)/zrpcd-%.x86_64.rpm $(QUAGGA_RPMS_DIR)/zrpcd-%.x86_64.rpm: @echo "Building ZRPC RPM" @./build_quagga.sh -a zrpc ############ # Quagga # ############ .PHONY: quagga-rpm quagga-rpm: $(QUAGGA_RPMS_DIR)/RPMS/x86_64/quagga-1.1.0_%.el7.centos.x86_64.rpm $(QUAGGA_RPMS_DIR)/RPMS/x86_64/quagga-1.1.0_%.el7.centos.x86_64.rpm: @echo "Building Quagga RPM" @./build_quagga.sh -a quagga ############### # Capnproto # ############### .PHONY: capnproto-rpm capnproto-rpm: $(QUAGGA_RPMS_DIR)/RPMS/x86_64/c-capnproto-%.x86_64.rpm $(QUAGGA_RPMS_DIR)/RPMS/x86_64/c-capnproto-%.x86_64.rpm: @echo "Building capnproto RPMs" @./build_quagga.sh -a capnproto ############ # Thrift # ############ .PHONY: thrift-rpm thrift-rpm: $(QUAGGA_RPMS_DIR)/RPMS/x86_64/thrift-%.x86_64.rpm $(QUAGGA_RPMS_DIR)/RPMS/x86_64/thrift-%.x86_64.rpm: @echo "Building Thrift RPMs" @./build_quagga.sh -a thrift