Re: [PATCH 01/11] RISC-V: drivers/iommu: Add RISC-V IOMMU - Ziommu support.

From: Conor Dooley
Date: Wed Aug 02 2023 - 16:25:45 EST


On Wed, Aug 02, 2023 at 01:15:22PM -0700, Tomasz Jeznach wrote:
> On Thu, Jul 27, 2023 at 7:42 PM Zong Li <zong.li@xxxxxxxxxx> wrote:
> >
> > On Thu, Jul 20, 2023 at 3:34 AM Tomasz Jeznach <tjeznach@xxxxxxxxxxxx> wrote:
> > >
> > > +static int riscv_iommu_platform_probe(struct platform_device *pdev)
> > > +{
> > > + struct device *dev = &pdev->dev;
> > > + struct riscv_iommu_device *iommu = NULL;
> > > + struct resource *res = NULL;
> > > + int ret = 0;
> > > +
> > > + iommu = devm_kzalloc(dev, sizeof(*iommu), GFP_KERNEL);
> > > + if (!iommu)
> > > + return -ENOMEM;
> > > +
> > > + iommu->dev = dev;
> > > + dev_set_drvdata(dev, iommu);
> > > +
> > > + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> > > + if (!res) {
> > > + dev_err(dev, "could not find resource for register region\n");
> > > + return -EINVAL;
> > > + }
> > > +
> > > + iommu->reg = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
> > > + if (IS_ERR(iommu->reg)) {
> > > + ret = dev_err_probe(dev, PTR_ERR(iommu->reg),
> > > + "could not map register region\n");
> > > + goto fail;
> > > + };
> > > +
> > > + iommu->reg_phys = res->start;
> > > +
> > > + ret = -ENODEV;
> > > +
> > > + /* Sanity check: Did we get the whole register space ? */
> > > + if ((res->end - res->start + 1) < RISCV_IOMMU_REG_SIZE) {
> > > + dev_err(dev, "device region smaller than register file (0x%llx)\n",
> > > + res->end - res->start);
> > > + goto fail;
> > > + }
> >
> > Could we assume that DT should be responsible for specifying the right size?
> >
>
> This only to validate DT provided info and driver expected register
> file size. Expectation is that DT will provide right size.

FWIW this check seems needless to me, it's not the kernels job to
validate the devicetree.

Attachment: signature.asc
Description: PGP signature