Skip to content

SCMI-Mediator add support for DomUs#214

Open
oleksiimoisieiev wants to merge 8 commits intoxen-troops:rpi5_devfrom
oleksiimoisieiev:scmi_rcar_rpi5
Open

SCMI-Mediator add support for DomUs#214
oleksiimoisieiev wants to merge 8 commits intoxen-troops:rpi5_devfrom
oleksiimoisieiev:scmi_rcar_rpi5

Conversation

@oleksiimoisieiev
Copy link
Copy Markdown

@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 <oleksii_moisieiev@epam.com>
Reviewed-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>
}

#ifdef CONFIG_HOST_DTB_EXPORT
#define HYPFS_PROPERTY_MAX_SIZE 4096
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

return 0;
}

#ifdef CONFIG_HOST_DTB_EXPORT
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

bootfdt.c maybe?


#ifdef CONFIG_SCMI_SMC
res = mem_permit_access(kinfo->d, kinfo->d->arch.sci_channel.paddr,
0x1000);
Copy link
Copy Markdown
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
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Author

Choose a reason for hiding this comment

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

added

Copy link
Copy Markdown
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
Copy Markdown
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

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Author

Choose a reason for hiding this comment

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

fixed

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 <oleksii_moisieiev@epam.com>
Reviewed-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>
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 <oleksii_moisieiev@epam.com>
Reviewed-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>
@oleksiimoisieiev
Copy link
Copy Markdown
Author

@lorc @GrygiriiS updated. ready to stage 2

@lorc
Copy link
Copy Markdown
Collaborator

lorc commented Oct 2, 2024

I see no new changes

@oleksiimoisieiev
Copy link
Copy Markdown
Author

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

Copy link
Copy Markdown
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
Copy Markdown
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.


#ifdef CONFIG_SCMI_SMC
res = mem_permit_access(kinfo->d, kinfo->d->arch.sci_channel.paddr,
0x1000);
Copy link
Copy Markdown
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 <oleksii_moisieiev@epam.com>
Reviewed-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>
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 <oleksii_moisieiev@epam.com>
Reviewed-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>
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 <oleksii_moisieiev@epam.com>
Reviewed-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>
Remove space before function definition.

Signed-off-by: Oleksii Moisieiev <oleksii_moisieiev@epam.com>
Reviewed-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>
@oleksiimoisieiev
Copy link
Copy Markdown
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
Copy Markdown
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 <volodymyr_babchuk@epam.com>

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Author

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

@lorc
Copy link
Copy Markdown
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
Copy Markdown
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 <oleksii_moisieiev@epam.com>
Reviewed-by: Volodymyr Babchuk <volodymyr_babchuk@epam.com>
@oleksiimoisieiev
Copy link
Copy Markdown
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