Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/arm/cortex Only allocate what we need for ITT tables
details: https://anonhg.NetBSD.org/src/rev/90309008f793
branches: trunk
changeset: 446102:90309008f793
user: jmcneill <jmcneill%NetBSD.org@localhost>
date: Fri Nov 23 16:01:27 2018 +0000
description:
Only allocate what we need for ITT tables
diffstat:
sys/arch/arm/cortex/gicv3_its.c | 27 +++++++++++++++++++--------
1 files changed, 19 insertions(+), 8 deletions(-)
diffs (83 lines):
diff -r aa4fd239ac0d -r 90309008f793 sys/arch/arm/cortex/gicv3_its.c
--- a/sys/arch/arm/cortex/gicv3_its.c Fri Nov 23 14:08:40 2018 +0000
+++ b/sys/arch/arm/cortex/gicv3_its.c Fri Nov 23 16:01:27 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: gicv3_its.c,v 1.6 2018/11/23 11:48:12 jmcneill Exp $ */
+/* $NetBSD: gicv3_its.c,v 1.7 2018/11/23 16:01:27 jmcneill Exp $ */
/*-
* Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -32,12 +32,13 @@
#define _INTR_PRIVATE
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: gicv3_its.c,v 1.6 2018/11/23 11:48:12 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gicv3_its.c,v 1.7 2018/11/23 16:01:27 jmcneill Exp $");
#include <sys/param.h>
#include <sys/kmem.h>
#include <sys/bus.h>
#include <sys/cpu.h>
+#include <sys/bitops.h>
#include <uvm/uvm.h>
@@ -281,19 +282,23 @@
return (b << 8) | (d << 3) | f;
}
-static void
-gicv3_its_device_map(struct gicv3_its *its, uint32_t devid)
+static int
+gicv3_its_device_map(struct gicv3_its *its, uint32_t devid, u_int count)
{
struct gicv3_its_device *dev;
LIST_FOREACH(dev, &its->its_devices, dev_list)
if (dev->dev_id == devid)
- return;
+ return EEXIST;
+
+ const u_int vectors = MAX(2, count);
+ if (!powerof2(vectors))
+ return EINVAL;
const uint64_t typer = gits_read_8(its, GITS_TYPER);
const u_int id_bits = __SHIFTOUT(typer, GITS_TYPER_ID_bits) + 1;
const u_int itt_entry_size = __SHIFTOUT(typer, GITS_TYPER_ITT_entry_size) + 1;
- const u_int itt_size = roundup2((itt_entry_size * (1 << id_bits)) / NBBY, GITS_ITT_ALIGN);
+ const u_int itt_size = roundup(vectors * itt_entry_size, GITS_ITT_ALIGN);
dev = kmem_alloc(sizeof(*dev), KM_SLEEP);
dev->dev_id = devid;
@@ -305,6 +310,8 @@
*/
gits_command_mapd(its, devid, dev->dev_itt.segs[0].ds_addr, id_bits - 1, true);
gits_wait(its);
+
+ return 0;
}
static void
@@ -414,7 +421,8 @@
const uint32_t devid = gicv3_its_devid(pa->pa_pc, pa->pa_tag);
- gicv3_its_device_map(its, devid);
+ if (gicv3_its_device_map(its, devid, *count) != 0)
+ return NULL;
vectors = kmem_alloc(sizeof(*vectors) * *count, KM_SLEEP);
for (n = 0; n < *count; n++) {
@@ -479,7 +487,10 @@
const uint32_t devid = gicv3_its_devid(pa->pa_pc, pa->pa_tag);
- gicv3_its_device_map(its, devid);
+ if (gicv3_its_device_map(its, devid, *count) != 0) {
+ bus_space_unmap(bst, bsh, bsz);
+ return NULL;
+ }
vectors = kmem_alloc(sizeof(*vectors) * *count, KM_SLEEP);
for (n = 0; n < *count; n++) {
Home |
Main Index |
Thread Index |
Old Index