Skip to content

Commit

Permalink
Update libmetal to version v2023.10.0 - 1.5.0.
Browse files Browse the repository at this point in the history
Signed-off-by: iabdalkader <[email protected]>
  • Loading branch information
iabdalkader committed Dec 27, 2023
1 parent c2ad368 commit 3be4bc0
Show file tree
Hide file tree
Showing 41 changed files with 2,630 additions and 2,287 deletions.
21 changes: 10 additions & 11 deletions libraries/openamp_arduino/src/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
*/

#include <string.h>
#include <metal/errno.h>
#include <metal/assert.h>
#include <metal/device.h>
#include <metal/errno.h>
#include <metal/list.h>
#include <metal/log.h>
#include <metal/sys.h>
Expand Down Expand Up @@ -43,11 +43,10 @@ int metal_bus_find(const char *name, struct metal_bus **result)

metal_list_for_each(&_metal.common.bus_list, node) {
bus = metal_container_of(node, struct metal_bus, node);
if (strcmp(bus->name, name) != 0)
continue;
if (result)
if (strcmp(bus->name, name) == 0 && result) {
*result = bus;
return 0;
return 0;
}
}
return -ENOENT;
}
Expand Down Expand Up @@ -106,10 +105,10 @@ int metal_generic_dev_open(struct metal_bus *bus, const char *dev_name,

metal_list_for_each(&_metal.common.generic_device_list, node) {
dev = metal_container_of(node, struct metal_device, node);
if (strcmp(dev->name, dev_name) != 0)
continue;
*device = dev;
return metal_generic_dev_sys_open(dev);
if (strcmp(dev->name, dev_name) == 0) {
*device = dev;
return metal_generic_dev_sys_open(dev);
}
}

return -ENODEV;
Expand All @@ -122,9 +121,9 @@ int metal_generic_dev_dma_map(struct metal_bus *bus,
int nents_in,
struct metal_sg *sg_out)
{
int i;
(void)bus;
(void)device;
int i;

if (sg_out != sg_in)
memcpy(sg_out, sg_in, nents_in*(sizeof(struct metal_sg)));
Expand All @@ -144,10 +143,10 @@ void metal_generic_dev_dma_unmap(struct metal_bus *bus,
struct metal_sg *sg,
int nents)
{
int i;
(void)bus;
(void)device;
(void)dir;
int i;

for (i = 0; i < nents; i++) {
metal_cache_invalidate(sg[i].virt, sg[i].len);
Expand Down
56 changes: 56 additions & 0 deletions libraries/openamp_arduino/src/dma.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2015, Xilinx Inc. and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#include <metal/errno.h>
#include <string.h>
#include <metal/device.h>
#include <metal/log.h>
#include <metal/dma.h>
#include <metal/atomic.h>

int metal_dma_map(struct metal_device *dev,
uint32_t dir,
struct metal_sg *sg_in,
int nents_in,
struct metal_sg *sg_out)
{
int nents_out;

if (!dev || !sg_in || !sg_out)
return -EINVAL;
if (!dev->bus->ops.dev_dma_map)
return -ENODEV;

/* memory barrier */
if (dir == METAL_DMA_DEV_R)
/* If it is device read, apply memory write fence. */
atomic_thread_fence(memory_order_release);
else
/* If it is device write or r/w, apply memory r/w fence. */
atomic_thread_fence(memory_order_acq_rel);
nents_out = dev->bus->ops.dev_dma_map(dev->bus,
dev, dir, sg_in, nents_in, sg_out);
return nents_out;
}

void metal_dma_unmap(struct metal_device *dev,
uint32_t dir,
struct metal_sg *sg,
int nents)
{
/* memory barrier */
if (dir == METAL_DMA_DEV_R)
/* If it is device read, apply memory write fence. */
atomic_thread_fence(memory_order_release);
else
/*If it is device write or r/w, apply memory r/w fence */
atomic_thread_fence(memory_order_acq_rel);

if (!dev || !dev->bus->ops.dev_dma_unmap || !sg)
return;
dev->bus->ops.dev_dma_unmap(dev->bus,
dev, dir, sg, nents);
}
2 changes: 1 addition & 1 deletion libraries/openamp_arduino/src/generic_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
int metal_generic_dev_sys_open(struct metal_device *dev)
{
struct metal_io_region *io;
unsigned i;
unsigned int i;

/* map I/O memory regions */
for (i = 0; i < dev->num_regions; i++) {
Expand Down
4 changes: 2 additions & 2 deletions libraries/openamp_arduino/src/generic_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ void metal_sys_io_mem_map(struct metal_io_region *io)
size_t psize;
size_t *va;

va = (size_t *)io->virt;
psize = io->size;
va = io->virt;
psize = (size_t)io->size;
if (psize) {
if (psize >> io->page_shift)
psize = (size_t)1 << io->page_shift;
Expand Down
7 changes: 7 additions & 0 deletions libraries/openamp_arduino/src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ int metal_init(const struct metal_init_params *params)
{
int error = 0;

if (_metal.common.ref_count++ != 0)
return 0;

memset(&_metal, 0, sizeof(_metal));

_metal.common.log_handler = params->log_handler;
Expand All @@ -24,11 +27,15 @@ int metal_init(const struct metal_init_params *params)
if (error)
return error;

++_metal.common.ref_count;
return error;
}

void metal_finish(void)
{
if (--_metal.common.ref_count != 0)
return;

metal_sys_finish();
memset(&_metal, 0, sizeof(_metal));
}
16 changes: 9 additions & 7 deletions libraries/openamp_arduino/src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@
* SPDX-License-Identifier: BSD-3-Clause
*/

#include <metal/errno.h>
#include <limits.h>
#include <metal/errno.h>
#include <metal/io.h>
#include <metal/sys.h>

void metal_io_init(struct metal_io_region *io, void *virt,
const metal_phys_addr_t *physmap, size_t size,
unsigned page_shift, unsigned int mem_flags,
unsigned int page_shift, unsigned int mem_flags,
const struct metal_io_ops *ops)
{
const struct metal_io_ops nops = {NULL, NULL, NULL, NULL, NULL, NULL};
const struct metal_io_ops nops = {
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
};

io->virt = virt;
io->physmap = physmap;
Expand All @@ -37,7 +39,7 @@ int metal_io_block_read(struct metal_io_region *io, unsigned long offset,
unsigned char *dest = dst;
int retlen;

if (offset > io->size)
if (!ptr)
return -ERANGE;
if ((offset + len) > io->size)
len = io->size - offset;
Expand Down Expand Up @@ -74,7 +76,7 @@ int metal_io_block_write(struct metal_io_region *io, unsigned long offset,
const unsigned char *source = src;
int retlen;

if (offset > io->size)
if (!ptr)
return -ERANGE;
if ((offset + len) > io->size)
len = io->size - offset;
Expand Down Expand Up @@ -110,7 +112,7 @@ int metal_io_block_set(struct metal_io_region *io, unsigned long offset,
unsigned char *ptr = metal_io_virt(io, offset);
int retlen = len;

if (offset > io->size)
if (!ptr)
return -ERANGE;
if ((offset + len) > io->size)
len = io->size - offset;
Expand All @@ -123,7 +125,7 @@ int metal_io_block_set(struct metal_io_region *io, unsigned long offset,
unsigned int i;

for (i = 1; i < sizeof(int); i++)
cint |= ((unsigned int)value << (8 * i));
cint |= ((unsigned int)value << (CHAR_BIT * i));

for (; len && ((uintptr_t)ptr % sizeof(int)); ptr++, len--)
*(unsigned char *)ptr = (unsigned char) value;
Expand Down
Loading

0 comments on commit 3be4bc0

Please sign in to comment.