Commit 5bab7864 authored by Konrad Rzeszutek Wilk's avatar Konrad Rzeszutek Wilk

xen/swiotlb: Move the error strings to its own function.

That way we can more easily reuse those errors when using the
late SWIOTLB init.
Acked-by: default avatarStefano Stabellini <stefano.stabellini@eu.citrix.com>
Signed-off-by: default avatarKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
parent 1cef36a5
...@@ -154,11 +154,33 @@ static unsigned long xen_set_nslabs(unsigned long nr_tbl) ...@@ -154,11 +154,33 @@ static unsigned long xen_set_nslabs(unsigned long nr_tbl)
return xen_io_tlb_nslabs << IO_TLB_SHIFT; return xen_io_tlb_nslabs << IO_TLB_SHIFT;
} }
enum xen_swiotlb_err {
XEN_SWIOTLB_UNKNOWN = 0,
XEN_SWIOTLB_ENOMEM,
XEN_SWIOTLB_EFIXUP
};
static const char *xen_swiotlb_error(enum xen_swiotlb_err err)
{
switch (err) {
case XEN_SWIOTLB_ENOMEM:
return "Cannot allocate Xen-SWIOTLB buffer\n";
case XEN_SWIOTLB_EFIXUP:
return "Failed to get contiguous memory for DMA from Xen!\n"\
"You either: don't have the permissions, do not have"\
" enough free memory under 4GB, or the hypervisor memory"\
" is too fragmented!";
default:
break;
}
return "";
}
void __init xen_swiotlb_init(int verbose) void __init xen_swiotlb_init(int verbose)
{ {
unsigned long bytes; unsigned long bytes;
int rc = -ENOMEM; int rc = -ENOMEM;
char *m = NULL; enum xen_swiotlb_err m_ret = XEN_SWIOTLB_UNKNOWN;
unsigned int repeat = 3; unsigned int repeat = 3;
xen_io_tlb_nslabs = swiotlb_nr_tbl(); xen_io_tlb_nslabs = swiotlb_nr_tbl();
...@@ -169,7 +191,7 @@ void __init xen_swiotlb_init(int verbose) ...@@ -169,7 +191,7 @@ void __init xen_swiotlb_init(int verbose)
*/ */
xen_io_tlb_start = alloc_bootmem_pages(PAGE_ALIGN(bytes)); xen_io_tlb_start = alloc_bootmem_pages(PAGE_ALIGN(bytes));
if (!xen_io_tlb_start) { if (!xen_io_tlb_start) {
m = "Cannot allocate Xen-SWIOTLB buffer!\n"; m_ret = XEN_SWIOTLB_ENOMEM;
goto error; goto error;
} }
xen_io_tlb_end = xen_io_tlb_start + bytes; xen_io_tlb_end = xen_io_tlb_start + bytes;
...@@ -181,10 +203,7 @@ void __init xen_swiotlb_init(int verbose) ...@@ -181,10 +203,7 @@ void __init xen_swiotlb_init(int verbose)
xen_io_tlb_nslabs); xen_io_tlb_nslabs);
if (rc) { if (rc) {
free_bootmem(__pa(xen_io_tlb_start), PAGE_ALIGN(bytes)); free_bootmem(__pa(xen_io_tlb_start), PAGE_ALIGN(bytes));
m = "Failed to get contiguous memory for DMA from Xen!\n"\ m_ret = XEN_SWIOTLB_EFIXUP;
"You either: don't have the permissions, do not have"\
" enough free memory under 4GB, or the hypervisor memory"\
"is too fragmented!";
goto error; goto error;
} }
start_dma_addr = xen_virt_to_bus(xen_io_tlb_start); start_dma_addr = xen_virt_to_bus(xen_io_tlb_start);
...@@ -199,8 +218,8 @@ void __init xen_swiotlb_init(int verbose) ...@@ -199,8 +218,8 @@ void __init xen_swiotlb_init(int verbose)
(xen_io_tlb_nslabs << IO_TLB_SHIFT) >> 20); (xen_io_tlb_nslabs << IO_TLB_SHIFT) >> 20);
goto retry; goto retry;
} }
xen_raw_printk("%s (rc:%d)", m, rc); xen_raw_printk("%s (rc:%d)", xen_swiotlb_error(m_ret), rc);
panic("%s (rc:%d)", m, rc); panic("%s (rc:%d)", xen_swiotlb_error(m_ret), rc);
} }
void * void *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment