FROM:https://blog.csdn.net/hongzg1982/article/details/56516147
Software Component Block Diagram
RPM(Resource Power Manager)是高通MSM平臺另外加的一塊芯片,雖然與AP芯片打包在一起,但其是一個獨立的ARM Core。之所以加這個東西,就是要控制整個電源相關的shared resources,比如ldo,clock。負責與SMP,MPM交互進入睡眠或者喚醒整個系統。
以下是高通文檔中對各個功能模塊的說明。
Kernel – DALSys-based lightweight kernel
RPM handler – RPM handler abstracts the RPM message protocol away
from other software
Drivers – Drivers for each of the resources supported by the RPM will
register with RPM handler to request notification when requests are
received for the resource which the driver controls
NPA – A driver may use the Node Power Architecture (NPA) to represent
resources controlled by the driver
Clock driver – RPM clock driver directly handles aggregating requests
from each of the masters for any of the systemwide clock resources
controlled by the RPM
Bus arbitration driver – RPM bus arbiter driver takes bus arbiter settings
as requests from the different masters in the system and aggregates them
to represent the frequency-independent system settings
PMIC – RPM PMIC driver directly aggregates requests from each of the
masters for any of the systemwide PMIC resources controlled by the RPM
Watch Dog driver – Watch Dog driver is a fail-safe for incorrect or stuck
code
MPM driver – Used to program the MPM hardware block during
systemwide sleep
RPM message driver – RPM message protocol driver abstracts the RPM
message protocol away from other subsystem software
Messaging Masters
與RPM通過shared memory region交互進行dynamic and static resource/power management的可以有很多種。
這個可以查看smd_type.h中的smd_channel_type。但目前看只有AP,MODEM,RIVA,TZ與RPM有交互,這個可以看message_ram_malloc()函數中的設置。
其實也可以間接從rpm_config.c文件中的SystempData temp_config_data這個變量中看出來到底有幾個部分是與RPM進行交互的。
RPM Initialization
在main.c文件中會逐個調用init_fcns[]變量中的函數進行初始化。當然也包括上面的資源的初始化。
const init_fcn init_fcns[] =
{
populate_image_header,
npa_init,
#if (!defined(MSM8909_STUBS) )
railway_init_v2,
#endif
PlatformInfo_Init, /* pm_init is using PlatformInfo APIs */
pm_init,//LDO等資源的註冊
acc_init,
#if (!defined(MSM8909_STUBS) )
railway_init_early_proxy_votes,
#endif
// xpu_init, /* cookie set here also indicates to SBL that railway is ready */
(init_fcn)Clock_Init, //Clock資源的註冊
__init_stack_chk_guard,
ddr_init,
smem_init,
init_smdl,
version_init, /* Needs to be after smem_init */
rpmserver_init,
rpm_server_init_done,
railway_init_proxies_and_pins,
#if (!defined(MSM8909_STUBS) )
rbcpr_init,
#endif
svs_init,
vmpm_init,
sleep_init,
#if (!defined(MSM8909_STUBS) )
QDSSInit,
#endif
exceptions_enable,
swevent_qdss_init,
icb_init,
#if (!defined(MSM8909_STUBS) )
debug_init,
system_db_init,
zqcal_task_init,
#endif
rpm_settling_timer_init,
gpio_toggle_init,
rpm_set_changer_common_init,
}
pm_init : LDO等資源的註冊,然後接收rpm_message。接收rpm_message的部分高通代碼沒有給,所以看不到,但從rpm log來看,是有接收處理並反饋的過程的。
107.764902: rpm_message_received (master: "APSS") (message id: 723)
107.764908: rpm_svs (mode: RPM_SVS_FAST) (reason: imminent processing)
107.764924: rpm_svs (mode: RPM_SVS_FAST) (reason: imminent processing)
107.764939: rpm_process_request (master: "APSS") (resource type: ldoa) (id: 14)
107.764942: rpm_xlate_request (resource type: ldoa) (resource id: 14)
107.764946: rpm_apply_request (resource type: ldoa) (resource id: 14)
107.765033: rpm_send_message_response (master: "APSS")
ldoa對應的resource type爲RPM_LDO_A_REQ。這個在pm_rom_device_init()裏的pm_rpm_ldo_register_resources(RPM_LDO_A_REQ, num_of_ldoa); 這裏被註冊,所以看進去最後xlate和apply最終都會被pm_rpm_ldo_translation()和pm_rpm_ldo_apply進行處理。pm_rpm_ldo_tranlation()讀取kvp內容,pm_rpm_ldo_apply最終把request的內容設置上去。
kernel端在msm-pm8916-rpm-regulator.dtsi文件中定如下ldo內容
1
2
2. (init_fcn)Clock_Init:Clock資源的註冊,這個過程和上面的也差不多
3. rpmserver_init:啓動接收message的進程
比如要設置LDO3的電壓和電流,kvp的內容如下:
{
“req\0” : {
{“rsrc” : “ldo\0”}
{“id” : 3}
{“set” : 0}
{“data” : {
{“uv\0\0” : 1100000}
{“mA\0\0” : 130}
}
}
}
}
RPM log裏邊顯示是APSS,這個在kernel裏邊也是有設置的,在msm-pm8916-rpm-regulator.dtsi裏的
rpm-regulator-ldoa14 {
compatible = "qcom,rpm-smd-regulator-resource";
qcom,resource-name = "ldoa";
qcom,resource-id = <14>;
qcom,regulator-type = <0>;
qcom,hpm-min-load = <5000>;
status = "disabled";
regulator-l14 {
compatible = "qcom,rpm-smd-regulator";
regulator-name = "8916_l14";
qcom,set = <3>;
status = "disabled";
};
};
MSM的retulator相關的驅動會讀取這個,如果有需要發請求的話,會根據這個dtsi的內容,組織kvp,然後通過rpm_request通道發過去。
rpm_request通道在rpm裏邊打開的地方是在rpm_handler.cpp裏邊的Hander::init()函數
void Handler::init()
{
smdlPort_ = smdl_open("rpm_requests",
rpm->ees[ee_].edge,
SMDL_OPEN_FLAGS_MODE_PACKET,
rpm->ees[ee_].smd_fifo_sz,
(smdl_callback_t)rpm_smd_handler,
this);
}
在對應的kernel端也有打開,可以參考msm8916.dtsi文件裏邊的設置。
rpm_bus: qcom,rpm-smd {
compatible = "qcom,rpm-smd";
rpm-channel-name = "rpm_requests";
rpm-channel-type = <15>; /* SMD_APPS_RPM */
};
以下是註冊資源的函數和資源的類型:
所有的資源都通過rpm_register_resource()函數註冊。這些資源包括clock, ldo等。具體可以看下面的類型定義。
typedef enum
{
RPM_TEST_REQ = 0x74736574, // 'test' in little endiant
RPM_CLOCK_0_REQ = 0x306b6c63, // 'clk0' in little endian; misc clocks [CXO, QDSS, dcvs.ena]
RPM_CLOCK_1_REQ = 0x316b6c63, // 'clk1' in little endian; bus clocks [pcnoc, snoc, sysmmnoc]
RPM_CLOCK_2_REQ = 0x326b6c63, // 'clk2' in little endian; memory clocks [bimc]
RPM_CLOCK_QPIC_REQ = 0x63697071, // 'qpic' in little endian; clock [qpic]
RPM_BUS_SLAVE_REQ = 0x766c7362, // 'bslv' in little endian
RPM_BUS_MASTER_REQ = 0x73616d62, // 'bmas' in little endian
RPM_BUS_SPDM_CLK_REQ = 0x63707362, // 'bspc' in little endian
RPM_BUS_MASTER_LATENCY_REQ = 0x74616c62, // 'blat' in little endian
RPM_SMPS_A_REQ = 0x61706D73, // 'smpa' in little endian
RPM_LDO_A_REQ = 0x616F646C, // 'ldoa' in little endian
RPM_NCP_A_REQ = 0x6170636E, // 'ncpa' in little endian
RPM_VS_A_REQ = 0x617376, // 'vsa' in little endian
RPM_CLK_BUFFER_A_REQ = 0x616B6C63, // 'clka' in little endian
RPM_BOOST_A_REQ = 0x61747362, // 'bsta' in little endian
RPM_SMPS_B_REQ = 0x62706D73, // 'smpb' in little endian
RPM_LDO_B_REQ = 0x626F646C, // 'ldob' in little endian
RPM_NCP_B_REQ = 0x6270636E, // 'ncpb' in little endian
RPM_VS_B_REQ = 0x627376, // 'vsb' in little endian
RPM_CLK_BUFFER_B_REQ = 0x626B6C63, // 'clk' in little endian
RPM_BOOST_B_REQ = 0x62747362, // 'bstb' in little endian
RPM_SWEVENT_REQ = 0x76657773, // 'swev' in little endian
RPM_OCMEM_POWER_REQ = 0x706d636f, // 憃cmp?in little endian
RPM_RBCPR_REQ = 0x727063, // 'cpr'in little endian
RPM_GPIO_TOGGLE_REQ = 0x6F697067, // 'gpio' in little endian:[gpio0,gpio1,gpio2]
} rpm_resource_type;
RPM Resouce Registration
rpm_register_resource():
Gpio_toggle.c (x:\j3_ctc\nhlos\rpm_proc\core\power\rpm\common): rpm_register_resource(RPM_GPIO_TOGGLE_REQ, 3, sizeof(gpio_toggle_inrep), gpio_toggle_xlate, gpio_toggle_apply, 0);
Icb_rpm_spdm_req.c (x:\j3_ctc\nhlos\rpm_proc\core\buses\icb\src\common): rpm_register_resource( RPM_BUS_SPDM_CLK_REQ,
Ocmem_resource.c (x:\j3_ctc\nhlos\rpm_proc\core\power\ocmem\src): rpm_register_resource(RPM_OCMEM_POWER_REQ, 3, sizeof(rpm_ocmem_vote_int_rep), rpm_ocmem_xlate, rpm_ocmem_apply, 0);
Pm_rpm_boost_trans_apply.c (x:\j3_ctc\nhlos\rpm_proc\core\systemdrivers\pmic\npa\src\rpm): rpm_register_resource(resourceType, num_npa_resources + 1 , sizeof(pm_npa_boost_int_rep), pm_rpm_boost_translation, pm_rpm_boost_apply, (void *)boost_data);
Pm_rpm_clk_buffer_trans_apply.c (x:\j3_ctc\nhlos\rpm_proc\core\systemdrivers\pmic\npa\src\rpm): rpm_register_resource(resourceType, num_npa_resources + 1,
Pm_rpm_ldo_trans_apply.c (x:\j3_ctc\nhlos\rpm_proc\core\systemdrivers\pmic\npa\src\rpm): rpm_register_resource(resourceType, num_npa_resources + 1, sizeof(pm_npa_ldo_int_rep), pm_rpm_ldo_translation, pm_rpm_ldo_apply, (void *)ldo_data);
Pm_rpm_smps_trans_apply.c (x:\j3_ctc\nhlos\rpm_proc\core\systemdrivers\pmic\npa\src\rpm): rpm_register_resource(resourceType, num_npa_resources + 1, sizeof(pm_npa_smps_int_rep), pm_rpm_smps_translation, pm_rpm_smps_apply, (void *)smps_data);
Pm_rpm_vs_trans_apply.c (x:\j3_ctc\nhlos\rpm_proc\core\systemdrivers\pmic\npa\src\rpm): rpm_register_resource(resourceType, num_npa_resources + 1, sizeof(pm_npa_vs_int_rep), pm_rpm_vs_translation, pm_rpm_vs_apply, (void *)vs_data);
Rpmserver.cpp (x:\j3_ctc\nhlos\rpm_proc\core\power\rpm\server):void rpm_register_resource
Rpmserver.h (x:\j3_ctc\nhlos\rpm_proc\core\api\power):void rpm_register_resource
Rpm_npa.cpp (x:\j3_ctc\nhlos\rpm_proc\core\power\rpm\server): rpm_register_resource(resource, num_npa_resources, sizeof(npa_request_data_t), rpm_npa_xlate, rpm_npa_apply, adapter);
Rpm_npa.cpp (x:\j3_ctc\nhlos\rpm_proc\core\power\rpm\server): rpm_register_resource(resource, num_npa_resources, sizeof(npa_request_data_t), rpm_npa_xlate, rpm_npa_apply, adapter);
Rpm_test_resource.cpp (x:\j3_ctc\nhlos\rpm_proc\core\power\rpm\server): rpm_register_resource(RPM_TEST_REQ, 1, 4, rpm_test_xlate, rpm_test_apply, 0);
Swevent.c (x:\j3_ctc\nhlos\rpm_proc\core\power\rpm\common): rpm_register_resource(RPM_SWEVENT_REQ, 1, sizeof(swevent_inrep), rpm_swevent_xlate, rpm_trace_control, 0);
所有的資源都是通過rpm_register_resource函數註冊。可以看到像RPM_BUS_SPDM_CLK_REQ,RPM_GPIO_TOGGLE_REQ都是通過這個接口直接註冊的。
NPA相關也是通過rpm_register_resource註冊,但是用了NPA的driver去實際註冊資源和使用資源。
NPA相關的兩個註冊接口是:rpm_create_npa_adapter(),rpm_create_npa_settling_adapter()。
可以看到這兩個就註冊了三個CLOCK相關的資源,
---- rpm_create_npa_adapter Matches (8 in 5 files) ----
ClockRPM.c : clk0_adapter = rpm_create_npa_adapter(RPM_CLOCK_0_REQ, 3); // Misc clocks: [CXO, QDSS, dcvs.ena]
ClockRPM.c : clk1_adapter = rpm_create_npa_adapter(RPM_CLOCK_1_REQ, 2); // Bus clocks: [pcnoc, snoc]
Rpmserver.h :rpm_npa_adapter rpm_create_npa_adapter(rpm_resource_type resource, unsigned num_npa_resources);
Rpm_npa.cpp :rpm_npa_adapter rpm_create_npa_adapter(rpm_resource_type resource, unsigned num_npa_resources)
---- rpm_create_npa_settling_adapter Matches (5 in 5 files) ----
ClockRPM.c : clk2_adapter = rpm_create_npa_settling_adapter(RPM_CLOCK_2_REQ, 1); // Memory clocks: [bimc ]
Rpmserver.h :rpm_npa_adapter rpm_create_npa_settling_adapter(rpm_resource_type resource, unsigned num_npa_resources);
Rpm_npa.cpp :rpm_npa_adapter rpm_create_npa_settling_adapter(rpm_resource_type resource, unsigned num_npa_resources)
NPA client的創建函數是:npa_create_sync_client()
NPA clien request的函數是:npa_issue_required_request()
NPA client創建並request這個資源,必須要適用像下面這樣的npa node。這個可以直接像下面這樣定義。然後再使用。步驟如下:
1.定義npa node definition
static npa_resource_definition sleep_uber_resource[] =
{
{
"/sleep/uber", /* Name */
"on/off", /* Units */
0x7, /* Max State */
&npa_or_plugin, /* Plugin */
NPA_RESOURCE_DEFAULT, /* Attributes */
NULL, /* User Data */
}
};
npa_node_definition sleep_uber_node =
{
"/node/sleep/uber", /* name */
sleep_uber_driver, /* driver_fcn */
NPA_NODE_DEFAULT, /* attributes */
NULL, /* data */
0, NULL, /* dependency count, dependency list */
NPA_ARRAY(sleep_uber_resource)
};
2.npa_define_node(&sleep_uber_node, initial_state, NULL),調用這個函數初始化這個NPA node
3.創建Client
uber_node_handle = npa_create_sync_client("/sleep/uber",
"sleep",
NPA_CLIENT_REQUIRED);
4.npa_issue_required_request(uber_node_handle, request) : request
RPM Resource handle
當子系統通過share memory發送請求給RPM。RPM負責處理這些請求並設置。RPM處理請求的流程如下:
SMD IRQ ->smd_isr()->rpm_smd_handler() [在Handler::init函數中註冊的,rpm_request channel的SMD處理函數]->Handler::queue()->schedule_me()->Handler::execute_until()->Handler::processMessage()->resource_ee_request()->發到每個資源註冊xlate然後再調用apply等
下面以高通控制DDR頻率(BIMC)的過程爲例,看一下kernel這邊怎麼發送請求給RPM的。
device tree設置如下:
cpubw: qcom,cpubw@0 {
reg = <0 4>;
compatible = "qcom,devbw";
governor = "cpufreq";
qcom,src-dst-ports = <1 512>;
qcom,active-only;
qcom,bw-tbl = //這個頻率表對應RPM中BIMC頻率表,不過刪掉了50MHz和9.6MHz。
/* 73 9.60 MHz */
/* 381 50MHz */
< 762 /* 100 MHz */>,
< 1525 /* 200 MHz */>,
< 3051 /* 400 MHz */>,
< 4066 /* 533 MHz */>;
};
對應的kernel代碼在devfeq_devbw.c文件。根據算法算出當前應該設定的ddr總線頻率之後,最後通過以下順序發消息給RPM。這裏暫時不討論按什麼規則選擇需要的頻率的,只看按什麼路徑發頻率給RPM的。
set_bw()->msm_bus_scale_client_update_request()->update_request_adhoc()[msm_bus_arb_adhoc.c]->update_path()->msm_bus_commit_data()->flush_bw_data()->send_rpm_msg()->msm_rpm_send_message()
System Sleep Overview
RPM除了對Clock和LDO等資源的管理之外,還管理整個系統睡眠。
可以看到睡眠並不是通過shared memory發送消息給RPM的,而是子系統通過設置對應的SPM,SPM觸發RPM相應的中斷來完成的。
kernel這邊設置spm的模式的設置如下:
enum {
MSM_SPM_MODE_DISABLED,
MSM_SPM_MODE_CLOCK_GATING,
MSM_SPM_MODE_RETENTION,
MSM_SPM_MODE_GDHS,
MSM_SPM_MODE_POWER_COLLAPSE,//設置成這個狀態之後,對應的SPM應該就會觸發RPM的對應的shutdown中斷
MSM_SPM_MODE_NR
};
rpm中,與哪幾個子系統傳遞接收message,然後和哪幾個子系統的SPM進行交互,交互的中斷號是多少的設置如下:
static SystemData temp_config_data =
{
.num_ees = 4, // 4 EE's, [apps, modem, pronto, tz]
.ees = (EEData[] ) {
[0] = {
.edge = SMD_APPS_RPM,
.smd_fifo_sz = 1024,
.ee_buflen = 256,
.priority = 4,
.wakeupInt = (1 << 5) | (1 << 7),
.spm = {
.numCores = 1,
.bringupInts = (unsigned[]) { 15 },
.bringupAcks = (unsigned[]) { 20 },
.shutdownInts = (unsigned[]) { 14 },//這個應該是SPM睡眠的中斷號
.shutdownAcks = (unsigned[]) { 4 },
},
},
[1] = {
.edge = SMD_MODEM_RPM,
.smd_fifo_sz = 1024,
.ee_buflen = 1024,
.priority = 2,
.wakeupInt = (1 << 13) | (1 << 15),
.spm = {
.numCores = 1,
.bringupInts = (unsigned[]) { 25 },
.bringupAcks = (unsigned[]) { 22 },
.shutdownInts = (unsigned[]) { 24 },
.shutdownAcks = (unsigned[]) { 6 },
},
},
[2] = {
.edge = SMD_RIVA_RPM,
.smd_fifo_sz = 1024,
.ee_buflen = 256,
.priority = 1,
.wakeupInt = (1 << 17) | (1 << 19),
.spm = {
.numCores = 1,
.bringupInts = (unsigned[]) { 31 },
.bringupAcks = (unsigned[]) { 23 },
.shutdownInts = (unsigned[]) { 30 },
.shutdownAcks = (unsigned[]) { 7 },
},
},
[3] = {
.edge = SMD_RPM_TZ,
.smd_fifo_sz = 1024,
.ee_buflen = 256,
.priority = 5,
.wakeupInt = 0,
.spm = {
.numCores = 0,
.bringupInts = (unsigned[]) { 31 },
.bringupAcks = (unsigned[]) { 23 },
.shutdownInts = (unsigned[]) { 30 },
.shutdownAcks = (unsigned[]) { 7 },
},
},
},
.supported_classes = SUPPORTED_CLASSES,
.supported_resources = SUPPORTED_RESOURCES,
.classes = (ResourceClassData[SUPPORTED_CLASSES]) { 0 },
.resources = (ResourceData[SUPPORTED_RESOURCES]) { 0 },
.resource_seeds = (int16_t[SUPPORTED_RESOURCES]) { 0 },
}
但還不知道這些中斷號到底怎麼來的,,中斷的個數都是1個,,這個怎麼來的也還是不知~
這些內容在rpm_spm_init中會讀取,然後設置中斷。shutdownISR對應的中斷處理函數爲rpm_spm_shutdown_high_isr。
這個中斷函數會調用rpm_spm_state_machine()處理RPM狀態機,進入或者阻止進入睡眠模式等。
void rpm_spm_state_machine(unsigned ee, rpm_spm_entry_reason reason)
{
INTLOCK();
bool changed_state = false;
EEData *ee_state = &(rpm->ees[ee]);
SetChanger *changer = ee_state->changer;
do
{
switch(ee_state->subsystem_status)
{
case SPM_AWAKE:
changed_state = FALSE;
if(0 == ee_state->num_active_cores)
{//等待所有的core都進入睡眠!!之後才能走到GOITONG TO SLEEP狀態!!
SPM_CHANGE_STATE(SPM_GOING_TO_SLEEP);
}
else
{
// We're awake, so make sure we keep up with any incoming bringup reqs.
rpm_acknowledge_spm_handshakes(ee);
}
break;
case SPM_GOING_TO_SLEEP:
if(changed_state)
{
// check for scheduled wakeup
uint64_t deadline = 0;
if(! rpm_get_wakeup_deadline(ee, deadline))
{
deadline = 0;
}
changer->setWakeTime (deadline);
// enqueue immediate set transition to sleep
changer->enqueue(RPM_SLEEP_SET, 0);
}
changed_state = FALSE;
// When we've finished selecting the sleep set, we're officially asleep.
if((SPM_TRANSITION_COMPLETE == reason) && (RPM_SLEEP_SET == changer->currentSet()))
{
SPM_CHANGE_STATE(SPM_SLEEPING);
}
// However, we might get a wakeup request before we've made it all the way to sleep.
if(SPM_BRINGUP_REQ == reason)
{
// Set the preempt flag; this will force the set change to recycle if
// it's currently running. It will notice the processor has woken up
// and stop performing its work.
theSchedule().preempt();
}
break;
case SPM_SLEEPING:
if(changed_state)
{
// check for scheduled wakeup
uint64_t deadline = changer->getWakeTime ();
// enqueue scheduled wakeup request
changer->enqueue(RPM_ACTIVE_SET, deadline);
}
changed_state = FALSE;
if(ee_state->num_active_cores > 0)
{
SPM_CHANGE_STATE(SPM_WAKING_UP);
}
break;
case SPM_WAKING_UP:
if(changed_state)
{
// work our way back to the active set
if(RPM_SLEEP_SET == changer->currentSet() || changer->inTransition())
{
changer->enqueue(RPM_ACTIVE_SET, 0);
}
}
changed_state = FALSE;
// check for completion
if(RPM_ACTIVE_SET == changer->currentSet() && !changer->inTransition())
{
SPM_CHANGE_STATE(SPM_AWAKE);
}
break;
}
} while(changed_state);
INTFREE();
}
最終會跑到SetChanger::enqueue()裏。
RPM與MPM的交互
RPM 狀態讀取
rpm的狀態讀取,在/d/rpm_stats裏邊可以讀到AP這邊設置的幾個APSS,MPSS,PRONTO等幾個對應的RPM狀態。
讀的內容當然也是從rpm_request這個shared memory裏邊讀的。相應的設置在msm8916-pm.dts文件裏邊有。
qcom,rpm-stats@29dba0 {
compatible = "qcom,rpm-stats";
reg = <0x29dba0 0x1000>;
reg-names = "phys_addr_base";
qcom,sleep-stats-version = <2>;
};
qcom,rpm-master-stats@60150 {
compatible = "qcom,rpm-master-stats";
reg = <0x60150 0x2030>;
qcom,masters = "APSS", "MPSS", "PRONTO";
qcom,master-stats-version = <2>;
qcom,master-offset = <4096>;
};
qcom,rpm-rbcpr-stats@0x29daa0 {
compatible = "qcom,rpmrbcpr-stats";
reg = <0x29daa0 0x1a0000>;
qcom,start-offset = <0x190010>;
};
---------------------
作者:honghong96
來源:CSDN
原文:https://blog.csdn.net/hongzg1982/article/details/56516147
版權聲明:本文爲博主原創文章,轉載請附上博文鏈接!