Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 30 Nov 2012 03:08:49 +0000 (UTC)
From:      Oleksandr Tymoshenko <gonzo@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r243690 - head/sys/dev/fdt
Message-ID:  <201211300308.qAU38nQe005118@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: gonzo
Date: Fri Nov 30 03:08:49 2012
New Revision: 243690
URL: http://svnweb.freebsd.org/changeset/base/243690

Log:
  Add fdt_get_reserved_regions function. API is simmilar to fdt_get_mem_regions
  It returns memory regions restricted from being used by kernel. These
  regions are dfined in "memreserve" property of root node in the same
  format as "reg" property of /memory node

Modified:
  head/sys/dev/fdt/fdt_common.c
  head/sys/dev/fdt/fdt_common.h

Modified: head/sys/dev/fdt/fdt_common.c
==============================================================================
--- head/sys/dev/fdt/fdt_common.c	Fri Nov 30 02:35:13 2012	(r243689)
+++ head/sys/dev/fdt/fdt_common.c	Fri Nov 30 03:08:49 2012	(r243690)
@@ -634,6 +634,66 @@ fdt_get_phyaddr(phandle_t node, device_t
 }
 
 int
+fdt_get_reserved_regions(struct mem_region *mr, int *mrcnt)
+{
+	pcell_t reserve[FDT_REG_CELLS * FDT_MEM_REGIONS];
+	pcell_t *reservep;
+	phandle_t memory, root;
+	uint32_t memory_size;
+	int addr_cells, size_cells;
+	int i, max_size, res_len, rv, tuple_size, tuples;
+
+	max_size = sizeof(reserve);
+	root = OF_finddevice("/");
+	memory = OF_finddevice("/memory");
+	if (memory == -1) {
+		rv = ENXIO;
+		goto out;
+	}
+
+	if ((rv = fdt_addrsize_cells(OF_parent(memory), &addr_cells,
+	    &size_cells)) != 0)
+		goto out;
+
+	if (addr_cells > 2) {
+		rv = ERANGE;
+		goto out;
+	}
+
+	tuple_size = sizeof(pcell_t) * (addr_cells + size_cells);
+
+	res_len = OF_getproplen(root, "memreserve");
+	if (res_len <= 0 || res_len > sizeof(reserve)) {
+		rv = ERANGE;
+		goto out;
+	}
+
+	if (OF_getprop(root, "memreserve", reserve, res_len) <= 0) {
+		rv = ENXIO;
+		goto out;
+	}
+
+	memory_size = 0;
+	tuples = res_len / tuple_size;
+	reservep = (pcell_t *)&reserve;
+	for (i = 0; i < tuples; i++) {
+
+		rv = fdt_data_to_res(reservep, addr_cells, size_cells,
+			(u_long *)&mr[i].mr_start, (u_long *)&mr[i].mr_size);
+
+		if (rv != 0)
+			goto out;
+
+		reservep += addr_cells + size_cells;
+	}
+
+	*mrcnt = i;
+	rv = 0;
+out:
+	return (rv);
+}
+
+int
 fdt_get_mem_regions(struct mem_region *mr, int *mrcnt, uint32_t *memsize)
 {
 	pcell_t reg[FDT_REG_CELLS * FDT_MEM_REGIONS];

Modified: head/sys/dev/fdt/fdt_common.h
==============================================================================
--- head/sys/dev/fdt/fdt_common.h	Fri Nov 30 02:35:13 2012	(r243689)
+++ head/sys/dev/fdt/fdt_common.h	Fri Nov 30 03:08:49 2012	(r243690)
@@ -90,6 +90,7 @@ int fdt_data_to_res(pcell_t *, int, int,
 int fdt_data_verify(void *, int);
 phandle_t fdt_find_compatible(phandle_t, const char *, int);
 int fdt_get_mem_regions(struct mem_region *, int *, uint32_t *);
+int fdt_get_reserved_regions(struct mem_region *, int *);
 int fdt_get_phyaddr(phandle_t, device_t, int *, void **);
 int fdt_get_range(phandle_t, int, u_long *, u_long *);
 int fdt_immr_addr(vm_offset_t);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201211300308.qAU38nQe005118>