commonlib: Prepare code to be included in cbfstool builds.
Some of the files need to be adjusted so that they can be used both in cbfstool as well as coreboot proper. For coreboot, add a <sys/types.h> file such that proper types can be included from both the tools and coreboot. The other chanes are to accomodate stricter checking in cbfstool. BUG=chrome-os-partner:48412 BUG=chromium:445938 BRANCH=None TEST=Built on glados including tools. Booted. Change-Id: I771c6675c64b8837f775427721dd3300a8fa1bc0 Signed-off-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: https://review.coreboot.org/12784 Tested-by: build bot (Jenkins) Reviewed-by: Martin Roth <martinroth@google.com> Reviewed-by: Patrick Georgi <pgeorgi@google.com>
This commit is contained in:
@ -2,7 +2,9 @@
|
|||||||
#define COMMONLIB_HELPERS_H
|
#define COMMONLIB_HELPERS_H
|
||||||
/* This file is for helpers for both coreboot firmware and its utilities. */
|
/* This file is for helpers for both coreboot firmware and its utilities. */
|
||||||
|
|
||||||
|
#ifndef ARRAY_SIZE
|
||||||
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
|
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
|
||||||
|
#endif
|
||||||
|
|
||||||
#define ALIGN(x,a) __ALIGN_MASK(x,(__typeof__(x))(a)-1UL)
|
#define ALIGN(x,a) __ALIGN_MASK(x,(__typeof__(x))(a)-1UL)
|
||||||
#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
|
#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
|
||||||
@ -54,4 +56,8 @@
|
|||||||
const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \
|
const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \
|
||||||
(type *)( (char *)__mptr - offsetof(type,member) );})
|
(type *)( (char *)__mptr - offsetof(type,member) );})
|
||||||
|
|
||||||
|
#ifndef __unused
|
||||||
|
#define __unused __attribute__((unused))
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* COMMONLIB_HELPERS_H */
|
#endif /* COMMONLIB_HELPERS_H */
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#ifndef _REGION_H_
|
#ifndef _REGION_H_
|
||||||
#define _REGION_H_
|
#define _REGION_H_
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <commonlib/mem_pool.h>
|
#include <commonlib/mem_pool.h>
|
||||||
|
@ -13,8 +13,8 @@
|
|||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <commonlib/helpers.h>
|
||||||
#include <commonlib/mem_pool.h>
|
#include <commonlib/mem_pool.h>
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
void *mem_pool_alloc(struct mem_pool *mp, size_t sz)
|
void *mem_pool_alloc(struct mem_pool *mp, size_t sz)
|
||||||
{
|
{
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <commonlib/helpers.h>
|
||||||
#include <commonlib/region.h>
|
#include <commonlib/region.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@ -133,16 +134,17 @@ void mem_region_device_init(struct mem_region_device *mdev, void *base,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void *mdev_mmap(const struct region_device *rd, size_t offset,
|
static void *mdev_mmap(const struct region_device *rd, size_t offset,
|
||||||
size_t size)
|
size_t size __unused)
|
||||||
{
|
{
|
||||||
const struct mem_region_device *mdev;
|
const struct mem_region_device *mdev;
|
||||||
|
|
||||||
mdev = container_of(rd, typeof(*mdev), rdev);
|
mdev = container_of(rd, __typeof__(*mdev), rdev);
|
||||||
|
|
||||||
return &mdev->base[offset];
|
return &mdev->base[offset];
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mdev_munmap(const struct region_device *rd, void *mapping)
|
static int mdev_munmap(const struct region_device * rd __unused,
|
||||||
|
void *mapping __unused)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -152,7 +154,7 @@ static ssize_t mdev_readat(const struct region_device *rd, void *b,
|
|||||||
{
|
{
|
||||||
const struct mem_region_device *mdev;
|
const struct mem_region_device *mdev;
|
||||||
|
|
||||||
mdev = container_of(rd, typeof(*mdev), rdev);
|
mdev = container_of(rd, __typeof__(*mdev), rdev);
|
||||||
|
|
||||||
memcpy(b, &mdev->base[offset], size);
|
memcpy(b, &mdev->base[offset], size);
|
||||||
|
|
||||||
@ -177,7 +179,7 @@ void *mmap_helper_rdev_mmap(const struct region_device *rd, size_t offset,
|
|||||||
struct mmap_helper_region_device *mdev;
|
struct mmap_helper_region_device *mdev;
|
||||||
void *mapping;
|
void *mapping;
|
||||||
|
|
||||||
mdev = container_of((void *)rd, typeof(*mdev), rdev);
|
mdev = container_of((void *)rd, __typeof__(*mdev), rdev);
|
||||||
|
|
||||||
mapping = mem_pool_alloc(&mdev->pool, size);
|
mapping = mem_pool_alloc(&mdev->pool, size);
|
||||||
|
|
||||||
@ -196,7 +198,7 @@ int mmap_helper_rdev_munmap(const struct region_device *rd, void *mapping)
|
|||||||
{
|
{
|
||||||
struct mmap_helper_region_device *mdev;
|
struct mmap_helper_region_device *mdev;
|
||||||
|
|
||||||
mdev = container_of((void *)rd, typeof(*mdev), rdev);
|
mdev = container_of((void *)rd, __typeof__(*mdev), rdev);
|
||||||
|
|
||||||
mem_pool_free(&mdev->pool, mapping);
|
mem_pool_free(&mdev->pool, mapping);
|
||||||
|
|
||||||
@ -212,7 +214,7 @@ static void *xlate_mmap(const struct region_device *rd, size_t offset,
|
|||||||
.size = size,
|
.size = size,
|
||||||
};
|
};
|
||||||
|
|
||||||
xldev = container_of(rd, typeof(*xldev), rdev);
|
xldev = container_of(rd, __typeof__(*xldev), rdev);
|
||||||
|
|
||||||
if (!is_subregion(&xldev->sub_region, &req))
|
if (!is_subregion(&xldev->sub_region, &req))
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -226,7 +228,7 @@ static int xlate_munmap(const struct region_device *rd, void *mapping)
|
|||||||
{
|
{
|
||||||
const struct xlate_region_device *xldev;
|
const struct xlate_region_device *xldev;
|
||||||
|
|
||||||
xldev = container_of(rd, typeof(*xldev), rdev);
|
xldev = container_of(rd, __typeof__(*xldev), rdev);
|
||||||
|
|
||||||
return rdev_munmap(xldev->access_dev, mapping);
|
return rdev_munmap(xldev->access_dev, mapping);
|
||||||
}
|
}
|
||||||
@ -240,7 +242,7 @@ static ssize_t xlate_readat(const struct region_device *rd, void *b,
|
|||||||
};
|
};
|
||||||
const struct xlate_region_device *xldev;
|
const struct xlate_region_device *xldev;
|
||||||
|
|
||||||
xldev = container_of(rd, typeof(*xldev), rdev);
|
xldev = container_of(rd, __typeof__(*xldev), rdev);
|
||||||
|
|
||||||
if (!is_subregion(&xldev->sub_region, &req))
|
if (!is_subregion(&xldev->sub_region, &req))
|
||||||
return -1;
|
return -1;
|
||||||
|
1
src/include/sys/types.h
Normal file
1
src/include/sys/types.h
Normal file
@ -0,0 +1 @@
|
|||||||
|
#include "../types.h"
|
Reference in New Issue
Block a user