PCI: epf-mhi: Make use of the alignment restriction from EPF core
Instead of hardcoding the alignment restriction in the EPF_MHI driver, make use of the info available from the EPF core that reflects the alignment restriction of the endpoint controller. For this purpose, let's introduce the get_align_offset() static function. [kwilczynski: update get_align_offset() to avoid issues on 32-bit architectures] Link: https://lore.kernel.org/linux-pci/20230717065459.14138-3-manivannan.sadhasivam@linaro.org Link: https://lore.kernel.org/linux-pci/20230826150626.23309-1-manivannan.sadhasivam@linaro.org Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org>
This commit is contained in:
parent
8cd2b8ce48
commit
d9d9f26f16
@ -92,6 +92,7 @@ static const struct pci_epf_mhi_ep_info sdx55_info = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct pci_epf_mhi {
|
struct pci_epf_mhi {
|
||||||
|
const struct pci_epc_features *epc_features;
|
||||||
const struct pci_epf_mhi_ep_info *info;
|
const struct pci_epf_mhi_ep_info *info;
|
||||||
struct mhi_ep_cntrl mhi_cntrl;
|
struct mhi_ep_cntrl mhi_cntrl;
|
||||||
struct pci_epf *epf;
|
struct pci_epf *epf;
|
||||||
@ -102,6 +103,11 @@ struct pci_epf_mhi {
|
|||||||
int irq;
|
int irq;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static size_t get_align_offset(struct pci_epf_mhi *epf_mhi, u64 addr)
|
||||||
|
{
|
||||||
|
return addr & (epf_mhi->epc_features->align -1);
|
||||||
|
}
|
||||||
|
|
||||||
static int __pci_epf_mhi_alloc_map(struct mhi_ep_cntrl *mhi_cntrl, u64 pci_addr,
|
static int __pci_epf_mhi_alloc_map(struct mhi_ep_cntrl *mhi_cntrl, u64 pci_addr,
|
||||||
phys_addr_t *paddr, void __iomem **vaddr,
|
phys_addr_t *paddr, void __iomem **vaddr,
|
||||||
size_t offset, size_t size)
|
size_t offset, size_t size)
|
||||||
@ -133,8 +139,7 @@ static int pci_epf_mhi_alloc_map(struct mhi_ep_cntrl *mhi_cntrl, u64 pci_addr,
|
|||||||
size_t size)
|
size_t size)
|
||||||
{
|
{
|
||||||
struct pci_epf_mhi *epf_mhi = to_epf_mhi(mhi_cntrl);
|
struct pci_epf_mhi *epf_mhi = to_epf_mhi(mhi_cntrl);
|
||||||
struct pci_epc *epc = epf_mhi->epf->epc;
|
size_t offset = get_align_offset(epf_mhi, pci_addr);
|
||||||
size_t offset = pci_addr & (epc->mem->window.page_size - 1);
|
|
||||||
|
|
||||||
return __pci_epf_mhi_alloc_map(mhi_cntrl, pci_addr, paddr, vaddr,
|
return __pci_epf_mhi_alloc_map(mhi_cntrl, pci_addr, paddr, vaddr,
|
||||||
offset, size);
|
offset, size);
|
||||||
@ -159,9 +164,7 @@ static void pci_epf_mhi_unmap_free(struct mhi_ep_cntrl *mhi_cntrl, u64 pci_addr,
|
|||||||
size_t size)
|
size_t size)
|
||||||
{
|
{
|
||||||
struct pci_epf_mhi *epf_mhi = to_epf_mhi(mhi_cntrl);
|
struct pci_epf_mhi *epf_mhi = to_epf_mhi(mhi_cntrl);
|
||||||
struct pci_epf *epf = epf_mhi->epf;
|
size_t offset = get_align_offset(epf_mhi, pci_addr);
|
||||||
struct pci_epc *epc = epf->epc;
|
|
||||||
size_t offset = pci_addr & (epc->mem->window.page_size - 1);
|
|
||||||
|
|
||||||
__pci_epf_mhi_unmap_free(mhi_cntrl, pci_addr, paddr, vaddr, offset,
|
__pci_epf_mhi_unmap_free(mhi_cntrl, pci_addr, paddr, vaddr, offset,
|
||||||
size);
|
size);
|
||||||
@ -185,7 +188,7 @@ static int pci_epf_mhi_read_from_host(struct mhi_ep_cntrl *mhi_cntrl, u64 from,
|
|||||||
void *to, size_t size)
|
void *to, size_t size)
|
||||||
{
|
{
|
||||||
struct pci_epf_mhi *epf_mhi = to_epf_mhi(mhi_cntrl);
|
struct pci_epf_mhi *epf_mhi = to_epf_mhi(mhi_cntrl);
|
||||||
size_t offset = from % SZ_4K;
|
size_t offset = get_align_offset(epf_mhi, from);
|
||||||
void __iomem *tre_buf;
|
void __iomem *tre_buf;
|
||||||
phys_addr_t tre_phys;
|
phys_addr_t tre_phys;
|
||||||
int ret;
|
int ret;
|
||||||
@ -213,7 +216,7 @@ static int pci_epf_mhi_write_to_host(struct mhi_ep_cntrl *mhi_cntrl,
|
|||||||
void *from, u64 to, size_t size)
|
void *from, u64 to, size_t size)
|
||||||
{
|
{
|
||||||
struct pci_epf_mhi *epf_mhi = to_epf_mhi(mhi_cntrl);
|
struct pci_epf_mhi *epf_mhi = to_epf_mhi(mhi_cntrl);
|
||||||
size_t offset = to % SZ_4K;
|
size_t offset = get_align_offset(epf_mhi, to);
|
||||||
void __iomem *tre_buf;
|
void __iomem *tre_buf;
|
||||||
phys_addr_t tre_phys;
|
phys_addr_t tre_phys;
|
||||||
int ret;
|
int ret;
|
||||||
@ -270,6 +273,10 @@ static int pci_epf_mhi_core_init(struct pci_epf *epf)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
epf_mhi->epc_features = pci_epc_get_features(epc, epf->func_no, epf->vfunc_no);
|
||||||
|
if (!epf_mhi->epc_features)
|
||||||
|
return -ENODATA;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user