[coreboot-gerrit] New patch to review for coreboot: region: add write support

Antonello Dettori (dev@dettori.io) gerrit at coreboot.org
Wed Jun 22 21:29:52 CEST 2016


Antonello Dettori (dev at dettori.io) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/15318

-gerrit

commit 7cf63ad9d20bd7d7327814db31955aa4e77ceb1f
Author: Antonello Dettori <dev at dettori.io>
Date:   Wed Jun 22 21:09:08 2016 +0200

    region: add write support
    
    Implement write support into the region_device_ops
    struct.
    
    Change-Id: Iac2cf32e523d2f19ee9e5feefe1fba8c68982f3d
    Signed-off-by: Antonello Dettori <dev at dettori.io>
---
 src/commonlib/include/commonlib/region.h | 10 ++++++-
 src/commonlib/region.c                   | 50 ++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+), 1 deletion(-)

diff --git a/src/commonlib/include/commonlib/region.h b/src/commonlib/include/commonlib/region.h
index 634132a..c83c169 100644
--- a/src/commonlib/include/commonlib/region.h
+++ b/src/commonlib/include/commonlib/region.h
@@ -48,6 +48,13 @@ int rdev_munmap(const struct region_device *rd, void *mapping);
 ssize_t rdev_readat(const struct region_device *rd, void *b, size_t offset,
 			size_t size);
 
+/*
+ * Returns < 0 on error otherwise returns size of data wrote at provided
+ * offset from the buffer passed.
+ */
+ssize_t rdev_write(const struct region_device *rd, void *b, size_t offset,
+			size_t size);
+
 
 /****************************************
  *  Implementation of a region device   *
@@ -67,6 +74,7 @@ struct region_device_ops {
 	void *(*mmap)(const struct region_device *, size_t, size_t);
 	int (*munmap)(const struct region_device *, void *);
 	ssize_t (*readat)(const struct region_device *, void *, size_t, size_t);
+	ssize_t (*write)(const struct region_device *, void *, size_t, size_t);
 };
 
 struct region {
@@ -170,7 +178,7 @@ void *mmap_helper_rdev_mmap(const struct region_device *, size_t, size_t);
 int mmap_helper_rdev_munmap(const struct region_device *, void *);
 
 /* A translated region device provides the ability to publish a region device
- * in one address space and use an access mechansim within another address
+ * in one address space and use an access mechanism within another address
  * space. The sub region is the window within the 1st address space and
  * the request is modified prior to accessing the second address space
  * provided by access_dev. */
diff --git a/src/commonlib/region.c b/src/commonlib/region.c
index 6f71074..9b4b2e5 100644
--- a/src/commonlib/region.c
+++ b/src/commonlib/region.c
@@ -103,6 +103,23 @@ ssize_t rdev_readat(const struct region_device *rd, void *b, size_t offset,
 	return rdev->ops->readat(rdev, b, req.offset, req.size);
 }
 
+ssize_t rdev_write(const struct region_device *rd, void *b, size_t offset,
+			size_t size)
+{
+	const struct region_device *rdev;
+	struct region req = {
+		.offset = offset,
+		.size = size,
+	};
+
+	if (!normalize_and_ok(&rd->region, &req))
+		return -1;
+
+	rdev = rdev_root(rd);
+
+	return rdev->ops->write(rdev, b, req.offset, req.size);
+}
+
 int rdev_chain(struct region_device *child, const struct region_device *parent,
 		size_t offset, size_t size)
 {
@@ -184,10 +201,23 @@ static ssize_t mdev_readat(const struct region_device *rd, void *b,
 	return size;
 }
 
+static ssize_t mdev_write(const struct region_device *rd, void *b,
+				size_t offset, size_t size)
+{
+	const struct mem_region_device *mdev;
+
+	mdev = container_of(rd, __typeof__(*mdev), rdev);
+
+	memcpy(&mdev->base[offset], b, size);
+
+	return size;
+}
+
 const struct region_device_ops mem_rdev_ops = {
 	.mmap = mdev_mmap,
 	.munmap = mdev_munmap,
 	.readat = mdev_readat,
+	.write = mdev_write,
 };
 
 void mmap_helper_device_init(struct mmap_helper_region_device *mdev,
@@ -275,8 +305,28 @@ static ssize_t xlate_readat(const struct region_device *rd, void *b,
 	return rdev_readat(xldev->access_dev, b, offset, size);
 }
 
+static ssize_t xlate_write(const struct region_device *rd, void *b,
+				size_t offset, size_t size)
+{
+	struct region req = {
+		.offset = offset,
+		.size = size,
+	};
+	const struct xlate_region_device *xldev;
+
+	xldev = container_of(rd, __typeof__(*xldev), rdev);
+
+	if (!is_subregion(&xldev->sub_region, &req))
+		return -1;
+
+	offset -= region_offset(&xldev->sub_region);
+
+	return rdev_write(xldev->access_dev, b, offset, size);
+}
+
 const struct region_device_ops xlate_rdev_ops = {
 	.mmap = xlate_mmap,
 	.munmap = xlate_munmap,
 	.readat = xlate_readat,
+	.write = xlate_write,
 };



More information about the coreboot-gerrit mailing list