irqchip/gic-v3-its: Generalize device table allocation

As we want to use 2-level tables for VCPUs, let's hack the device
table allocator in order to make it slightly more generic. It
will get reused in subsequent patches.

Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>

+16 -10
+16 -10
drivers/irqchip/irq-gic-v3-its.c
··· 1392 1392 return NULL; 1393 1393 } 1394 1394 1395 - static bool its_alloc_device_table(struct its_node *its, u32 dev_id) 1395 + static bool its_alloc_table_entry(struct its_baser *baser, u32 id) 1396 1396 { 1397 - struct its_baser *baser; 1398 1397 struct page *page; 1399 1398 u32 esz, idx; 1400 1399 __le64 *table; 1401 1400 1402 - baser = its_get_baser(its, GITS_BASER_TYPE_DEVICE); 1403 - 1404 - /* Don't allow device id that exceeds ITS hardware limit */ 1405 - if (!baser) 1406 - return (ilog2(dev_id) < its->device_ids); 1407 - 1408 1401 /* Don't allow device id that exceeds single, flat table limit */ 1409 1402 esz = GITS_BASER_ENTRY_SIZE(baser->val); 1410 1403 if (!(baser->val & GITS_BASER_INDIRECT)) 1411 - return (dev_id < (PAGE_ORDER_TO_SIZE(baser->order) / esz)); 1404 + return (id < (PAGE_ORDER_TO_SIZE(baser->order) / esz)); 1412 1405 1413 1406 /* Compute 1st level table index & check if that exceeds table limit */ 1414 - idx = dev_id >> ilog2(baser->psz / esz); 1407 + idx = id >> ilog2(baser->psz / esz); 1415 1408 if (idx >= (PAGE_ORDER_TO_SIZE(baser->order) / GITS_LVL1_ENTRY_SIZE)) 1416 1409 return false; 1417 1410 ··· 1431 1438 } 1432 1439 1433 1440 return true; 1441 + } 1442 + 1443 + static bool its_alloc_device_table(struct its_node *its, u32 dev_id) 1444 + { 1445 + struct its_baser *baser; 1446 + 1447 + baser = its_get_baser(its, GITS_BASER_TYPE_DEVICE); 1448 + 1449 + /* Don't allow device id that exceeds ITS hardware limit */ 1450 + if (!baser) 1451 + return (ilog2(dev_id) < its->device_ids); 1452 + 1453 + return its_alloc_table_entry(baser, dev_id); 1434 1454 } 1435 1455 1436 1456 static struct its_device *its_create_device(struct its_node *its, u32 dev_id,