Skip to content

Commit 994ea2f

Browse files
legoatermpe
authored andcommitted
powerpc/xive: introduce a common routine xive_queue_page_alloc()
This routine will be used in the spapr backend. Also introduce a short xive_alloc_order() helper. Signed-off-by: Cédric Le Goater <[email protected]> Reviewed-by: David Gibson <[email protected]> Acked-by: Benjamin Herrenschmidt <[email protected]> Signed-off-by: Michael Ellerman <[email protected]>
1 parent 3b79b26 commit 994ea2f

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

arch/powerpc/sysdev/xive/common.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,22 @@ bool __init xive_core_init(const struct xive_ops *ops, void __iomem *area, u32 o
14281428
return true;
14291429
}
14301430

1431+
__be32 *xive_queue_page_alloc(unsigned int cpu, u32 queue_shift)
1432+
{
1433+
unsigned int alloc_order;
1434+
struct page *pages;
1435+
__be32 *qpage;
1436+
1437+
alloc_order = xive_alloc_order(queue_shift);
1438+
pages = alloc_pages_node(cpu_to_node(cpu), GFP_KERNEL, alloc_order);
1439+
if (!pages)
1440+
return ERR_PTR(-ENOMEM);
1441+
qpage = (__be32 *)page_address(pages);
1442+
memset(qpage, 0, 1 << queue_shift);
1443+
1444+
return qpage;
1445+
}
1446+
14311447
static int __init xive_off(char *arg)
14321448
{
14331449
xive_cmdline_disabled = true;

arch/powerpc/sysdev/xive/native.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -202,17 +202,12 @@ EXPORT_SYMBOL_GPL(xive_native_disable_queue);
202202
static int xive_native_setup_queue(unsigned int cpu, struct xive_cpu *xc, u8 prio)
203203
{
204204
struct xive_q *q = &xc->queue[prio];
205-
unsigned int alloc_order;
206-
struct page *pages;
207205
__be32 *qpage;
208206

209-
alloc_order = (xive_queue_shift > PAGE_SHIFT) ?
210-
(xive_queue_shift - PAGE_SHIFT) : 0;
211-
pages = alloc_pages_node(cpu_to_node(cpu), GFP_KERNEL, alloc_order);
212-
if (!pages)
213-
return -ENOMEM;
214-
qpage = (__be32 *)page_address(pages);
215-
memset(qpage, 0, 1 << xive_queue_shift);
207+
qpage = xive_queue_page_alloc(cpu, xive_queue_shift);
208+
if (IS_ERR(qpage))
209+
return PTR_ERR(qpage);
210+
216211
return xive_native_configure_queue(get_hard_smp_processor_id(cpu),
217212
q, prio, qpage, xive_queue_shift, false);
218213
}
@@ -227,8 +222,7 @@ static void xive_native_cleanup_queue(unsigned int cpu, struct xive_cpu *xc, u8
227222
* from an IPI and iounmap isn't safe
228223
*/
229224
__xive_native_disable_queue(get_hard_smp_processor_id(cpu), q, prio);
230-
alloc_order = (xive_queue_shift > PAGE_SHIFT) ?
231-
(xive_queue_shift - PAGE_SHIFT) : 0;
225+
alloc_order = xive_alloc_order(xive_queue_shift);
232226
free_pages((unsigned long)q->qpage, alloc_order);
233227
q->qpage = NULL;
234228
}

arch/powerpc/sysdev/xive/xive-internal.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ struct xive_ops {
5656

5757
bool xive_core_init(const struct xive_ops *ops, void __iomem *area, u32 offset,
5858
u8 max_prio);
59+
__be32 *xive_queue_page_alloc(unsigned int cpu, u32 queue_shift);
60+
61+
static inline u32 xive_alloc_order(u32 queue_shift)
62+
{
63+
return (queue_shift > PAGE_SHIFT) ? (queue_shift - PAGE_SHIFT) : 0;
64+
}
5965

6066
extern bool xive_cmdline_disabled;
6167

0 commit comments

Comments
 (0)