Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCMI-Mediator add support for DomUs #214

Open
wants to merge 8 commits into
base: rpi5_dev
Choose a base branch
from

Conversation

oleksiimoisieiev
Copy link

@oleksiimoisieiev oleksiimoisieiev commented Sep 30, 2024

This feature is adding SCMI mediator support for DomU. Since toolstack is not using in current rpi5 setup - there is no posibility to test it on rpi5. But this approach was tested on R-Car Gen3 board which is using toolstack to start the Domains.
This pr was made to make SCMI-Mediator support generic.

Config parameters needed to enable scmi feature:

CONFIG_ARM_SCI=y                                                                
CONFIG_SCMI_SMC=y                                                               
CONFIG_HOST_DTB_EXPORT=y                                                        
CONFIG_ACCESS_CONTROLLER=y 

DomU configuration:

arm_sci="scmi_smc"

DomU partial dtb:

/{
      firmware {
            scmi {
                  scmi_reset:protocol@16 {
                  };
                  scmi_pinctrl:protocol@19 {
                               mux1: mux1 {
                               };
                               mux2: mux2 {
                               };
                  };
      };
      passthrough {
         dev1 {
               resets = <&scmi_reset 1>;
               pinctrl-0 = <&mux1>;
         };
         dev2 {
               pinctrl-0 = <&mux2>;
         };
      };
};

TODO:

  • after review make a PR to xen-4.19-xt
    Postponed:
  • add new syscall to flask.

libxenhypfs will return blob properties as is. This output can be used
to retrieve information from the hypfs. Caller is responsible for
parsing property value.

Signed-off-by: Oleksii Moisieiev <[email protected]>
Reviewed-by: Volodymyr Babchuk <[email protected]>
@@ -698,6 +702,27 @@ int arch_sanitise_domain_config(struct xen_domctl_createdomain *config)
return 0;
}

#ifdef CONFIG_HOST_DTB_EXPORT
#define HYPFS_PROPERTY_MAX_SIZE 4096
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that DTB is much bigger than 4k. Also, naming is quite ambiguous. It just says "hypfs property". Which property exactly?

I believe, this is the leftover from your previous version. But in this version it makes no sense

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry. it's leftover. I've made HOST_DTB_MAX_SIZE config parameter

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with default as 8192. but probably 4096 is enough because current dtb in rcar is 2150

@@ -698,6 +702,27 @@ int arch_sanitise_domain_config(struct xen_domctl_createdomain *config)
return 0;
}

#ifdef CONFIG_HOST_DTB_EXPORT
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why it is living in the middle of domain.c? This file is for low-level domain state manipulation

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't find a better place. What do you suggest?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bootfdt.c maybe?

@@ -1741,6 +1755,12 @@ static int __init handle_node(struct domain *d, struct kernel_info *kinfo,
*/
evtchn_allocate(d);

#ifdef CONFIG_SCMI_SMC
res = mem_permit_access(kinfo->d, kinfo->d->arch.sci_channel.paddr,
0x1000);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please no magic values

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is still constant 0x1000

if ( res )
return res;

return map_regions_p2mt(d, gaddr_to_gfn(addr), PFN_DOWN(len),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should you remove iomem access permission if this call is failed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see where it was fixed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merged these changes to wrong commit. I'm sorry... now fixec

@@ -16,10 +16,13 @@ int __init scmi_dt_make_shmem_node(struct kernel_info *kinfo);
int __init scmi_dt_create_node(struct kernel_info *kinfo);
int __init scmi_dt_scan_node(struct kernel_info *kinfo, void *pfdt,
int nodeoff);
int __init scmi_dt_set_phandle(struct kernel_info *kinfo,
const char *name);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting is not consistent with the previous lines.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

int r;

if (fdt_magic(fdt) != FDT_MAGIC) {
LOG(ERROR, "Partial FDT is not a valid Flat Device Tree");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the partial device tree

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


r = fdt_check_header(fdt);
if (r) {
LOG(ERROR, "Failed to check the partial FDT (%d)", r);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the partial device tree

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

goto out;
}

nodeoff = get_path_nodeoff("/scmi", pfdt);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be /firmware/scmi ? I believe we discussed this at the daily call

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup. sorry. it's leftover

}

nodeoff = get_path_nodeoff("/scmi", pfdt);
if ( nodeoff <= 0 ) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

coding style

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2fixed

sci_info->paddr = d->arch.sci_channel.paddr;
sci_info->func_id = d->arch.sci_channel.guest_func_id;
#endif /* CONFIG_ARM_SCI */
return 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you need to return -ENODEV if CONFIG_ARM_SCI is not enabled or SCI is not enabled for the domain

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the second part of my comment? What if SCI is not enabled for that particular domain? It will have no valid paddr and func id in that case

return 0;
}


Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove extra enter

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

return subarch_do_domctl(domctl, d, u_domctl);
}
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove leftover

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

If enabled, host device-tree will be exported to hypfs and can be
accessed through /devicetree path.
Exported device-tree has the same format, as the device-tree
exported to the sysfs by the Linux kernel.
This is useful when XEN toolstack needs an access to the host device-tree.

Signed-off-by: Oleksii Moisieiev <[email protected]>
Reviewed-by: Volodymyr Babchuk <[email protected]>
This enumeration sets SCI type for the domain. Currently there is
two possible options: either 'none' or 'scmi_smc'.

'none' is the default value and it disables SCI support at all.

'scmi_smc' enables access to the Firmware from the domains using SCMI
protocol and SMC as transport.

Signed-off-by: Oleksii Moisieiev <[email protected]>
Reviewed-by: Volodymyr Babchuk <[email protected]>
@oleksiimoisieiev
Copy link
Author

@lorc @GrygiriiS updated. ready to stage 2

@lorc
Copy link
Collaborator

lorc commented Oct 2, 2024

I see no new changes

@oleksiimoisieiev
Copy link
Author

I'm really sorry... pushed to another branch... Updated @lorc

Copy link
Collaborator

@lorc lorc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you are missing some fixes, although you said that you fixed it

if ( res )
return res;

return map_regions_p2mt(d, gaddr_to_gfn(addr), PFN_DOWN(len),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see where it was fixed.

@@ -1741,6 +1755,12 @@ static int __init handle_node(struct domain *d, struct kernel_info *kinfo,
*/
evtchn_allocate(d);

#ifdef CONFIG_SCMI_SMC
res = mem_permit_access(kinfo->d, kinfo->d->arch.sci_channel.paddr,
0x1000);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is still constant 0x1000

Mapping for the hardware domain should be done during domain
construciton as it is done for other domains.

Signed-off-by: Oleksii Moisieiev <[email protected]>
Reviewed-by: Volodymyr Babchuk <[email protected]>
Integration of the SCMI-Mediator feature to the Domain-0 construction
process. It includes shared memory node creation and mapping with
phandle update on the scmi node.
When creating hardware domain there is a need to set correct phandle
to the "shmem" property on the scmi node. Shared memory node is
generated while scmi node is copied as is from Xen device-tree.
Correct shmem phandle is set during domain device-tree processing.

Signed-off-by: Oleksii Moisieiev <[email protected]>
Reviewed-by: Volodymyr Babchuk <[email protected]>
Assgin devices to the access-controller during Domain-0 build.
This registers devices in the SCMI server for the Domain-0.

Signed-off-by: Oleksii Moisieiev <[email protected]>
Reviewed-by: Volodymyr Babchuk <[email protected]>
Remove space before function definition.

Signed-off-by: Oleksii Moisieiev <[email protected]>
Reviewed-by: Volodymyr Babchuk <[email protected]>
@oleksiimoisieiev
Copy link
Author

Fixed all. Merged changes to the wrong commit. I think once Review is finished. I will make a pr to 4.19-xt0.1 with already reviewed code

Copy link
Collaborator

@lorc lorc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the last two comments resolved:

Reviewed-by: Volodymyr Babchuk <[email protected]>

sci_info->paddr = d->arch.sci_channel.paddr;
sci_info->func_id = d->arch.sci_channel.guest_func_id;
#endif /* CONFIG_ARM_SCI */
return 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the second part of my comment? What if SCI is not enabled for that particular domain? It will have no valid paddr and func id in that case


phandle = fdt_get_phandle(pfdt, node_next);

rc = fdt_get_path(pfdt, node_next, full_name, 128);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least use sizeof(full_name) here. No need for magic numbers.

@oleksiimoisieiev
Copy link
Author

In reply to comment: #214 (comment)
I'm returning -ENODEV in this case.

@lorc
Copy link
Collaborator

lorc commented Oct 4, 2024

I'm returning -ENODEV in this case.

Where?

Imagine you have purely virtual DomU without access to hardware. It does not need access to SCMI and SCMI should be disabled for this domain. In this case this domctl should return EINVAL or ENODEV or some other error.

sci_info->func_id = d->arch.sci_channel.guest_func_id;
return 0;
#else
return -ENODEV;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is some weird github twist... probably.

Integration of the SCMI mediator with xen libs:
- add hypercalls to aquire SCI channel and set device permissions
for DomUs;
- add SCMI_SMC nodes to DomUs device-tree based on partial device-tree;
- SCI requests redirection from DomUs to Firmware.

Signed-off-by: Oleksii Moisieiev <[email protected]>
Reviewed-by: Volodymyr Babchuk <[email protected]>
@oleksiimoisieiev
Copy link
Author

#214 (comment)

fixed.
Adding rb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants