1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Copyright (C) 2023 Google LLC 4 * Author: Mostafa Saleh <smostafa@google.com> 5 */ 6 7 #include <nvhe/pkvm.h> 8 9 struct hvc_power_domain { 10 struct kvm_power_domain *pd; 11 const struct kvm_power_domain_ops *ops; 12 }; 13 14 struct hvc_power_domain handlers[MAX_POWER_DOMAINS]; 15 pkvm_init_hvc_pd(struct kvm_power_domain * pd,const struct kvm_power_domain_ops * ops)16int pkvm_init_hvc_pd(struct kvm_power_domain *pd, 17 const struct kvm_power_domain_ops *ops) 18 { 19 if (pd->device_id >= MAX_POWER_DOMAINS) 20 return -E2BIG; 21 22 handlers[pd->device_id].ops = ops; 23 handlers[pd->device_id].pd = pd; 24 25 return 0; 26 } 27 pkvm_host_hvc_pd(u64 device_id,u64 on)28int pkvm_host_hvc_pd(u64 device_id, u64 on) 29 { 30 struct hvc_power_domain *pd; 31 32 if (device_id >= MAX_POWER_DOMAINS) 33 return -E2BIG; 34 35 device_id = array_index_nospec(device_id, MAX_POWER_DOMAINS); 36 pd = &handlers[device_id]; 37 38 if (!pd->ops) 39 return -ENOENT; 40 41 if (on) 42 pd->ops->power_on(pd->pd); 43 else 44 pd->ops->power_off(pd->pd); 45 46 return 0; 47 } 48