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 {
|
||||
const struct pci_epc_features *epc_features;
|
||||
const struct pci_epf_mhi_ep_info *info;
|
||||
struct mhi_ep_cntrl mhi_cntrl;
|
||||
struct pci_epf *epf;
|
||||
@ -102,6 +103,11 @@ struct pci_epf_mhi {
|
||||
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,
|
||||
phys_addr_t *paddr, void __iomem **vaddr,
|
||||
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)
|
||||
{
|
||||
struct pci_epf_mhi *epf_mhi = to_epf_mhi(mhi_cntrl);
|
||||
struct pci_epc *epc = epf_mhi->epf->epc;
|
||||
size_t offset = pci_addr & (epc->mem->window.page_size - 1);
|
||||
size_t offset = get_align_offset(epf_mhi, pci_addr);
|
||||
|
||||
return __pci_epf_mhi_alloc_map(mhi_cntrl, pci_addr, paddr, vaddr,
|
||||
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)
|
||||
{
|
||||
struct pci_epf_mhi *epf_mhi = to_epf_mhi(mhi_cntrl);
|
||||
struct pci_epf *epf = epf_mhi->epf;
|
||||
struct pci_epc *epc = epf->epc;
|
||||
size_t offset = pci_addr & (epc->mem->window.page_size - 1);
|
||||
size_t offset = get_align_offset(epf_mhi, pci_addr);
|
||||
|
||||
__pci_epf_mhi_unmap_free(mhi_cntrl, pci_addr, paddr, vaddr, offset,
|
||||
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)
|
||||
{
|
||||
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;
|
||||
phys_addr_t tre_phys;
|
||||
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)
|
||||
{
|
||||
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;
|
||||
phys_addr_t tre_phys;
|
||||
int ret;
|
||||
@ -270,6 +273,10 @@ static int pci_epf_mhi_core_init(struct pci_epf *epf)
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user