arm-trusted-firmware/drivers/st/io/io_mmc.c
Antonio Nino Diaz 09d40e0e08 Sanitise includes across codebase
Enforce full include path for includes. Deprecate old paths.

The following folders inside include/lib have been left unchanged:

- include/lib/cpus/${ARCH}
- include/lib/el3_runtime/${ARCH}

The reason for this change is that having a global namespace for
includes isn't a good idea. It defeats one of the advantages of having
folders and it introduces problems that are sometimes subtle (because
you may not know the header you are actually including if there are two
of them).

For example, this patch had to be created because two headers were
called the same way: e0ea0928d5 ("Fix gpio includes of mt8173 platform
to avoid collision."). More recently, this patch has had similar
problems: 46f9b2c3a2 ("drivers: add tzc380 support").

This problem was introduced in commit 4ecca33988 ("Move include and
source files to logical locations"). At that time, there weren't too
many headers so it wasn't a real issue. However, time has shown that
this creates problems.

Platforms that want to preserve the way they include headers may add the
removed paths to PLAT_INCLUDES, but this is discouraged.

Change-Id: I39dc53ed98f9e297a5966e723d1936d6ccf2fc8f
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
2019-01-04 10:43:17 +00:00

127 lines
2.9 KiB
C

/*
* Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <assert.h>
#include <errno.h>
#include <string.h>
#include <common/debug.h>
#include <drivers/io/io_driver.h>
#include <drivers/io/io_storage.h>
#include <drivers/mmc.h>
#include <drivers/st/io_mmc.h>
#include <drivers/st/stm32_sdmmc2.h>
/* SDMMC device functions */
static int mmc_dev_open(const uintptr_t init_params, io_dev_info_t **dev_info);
static int mmc_block_open(io_dev_info_t *dev_info, const uintptr_t spec,
io_entity_t *entity);
static int mmc_dev_init(io_dev_info_t *dev_info, const uintptr_t init_params);
static int mmc_block_seek(io_entity_t *entity, int mode, ssize_t offset);
static int mmc_block_read(io_entity_t *entity, uintptr_t buffer, size_t length,
size_t *length_read);
static int mmc_block_close(io_entity_t *entity);
static int mmc_dev_close(io_dev_info_t *dev_info);
static io_type_t device_type_mmc(void);
static ssize_t seek_offset;
static const io_dev_connector_t mmc_dev_connector = {
.dev_open = mmc_dev_open
};
static const io_dev_funcs_t mmc_dev_funcs = {
.type = device_type_mmc,
.open = mmc_block_open,
.seek = mmc_block_seek,
.size = NULL,
.read = mmc_block_read,
.write = NULL,
.close = mmc_block_close,
.dev_init = mmc_dev_init,
.dev_close = mmc_dev_close,
};
static const io_dev_info_t mmc_dev_info = {
.funcs = &mmc_dev_funcs,
.info = 0,
};
/* Identify the device type as mmc device */
static io_type_t device_type_mmc(void)
{
return IO_TYPE_MMC;
}
/* Open a connection to the mmc device */
static int mmc_dev_open(const uintptr_t init_params, io_dev_info_t **dev_info)
{
assert(dev_info != NULL);
*dev_info = (io_dev_info_t *)&mmc_dev_info;
return 0;
}
static int mmc_dev_init(io_dev_info_t *dev_info, const uintptr_t init_params)
{
return 0;
}
/* Close a connection to the mmc device */
static int mmc_dev_close(io_dev_info_t *dev_info)
{
return 0;
}
/* Open a file on the mmc device */
static int mmc_block_open(io_dev_info_t *dev_info, const uintptr_t spec,
io_entity_t *entity)
{
seek_offset = 0;
return 0;
}
/* Seek to a particular file offset on the mmc device */
static int mmc_block_seek(io_entity_t *entity, int mode, ssize_t offset)
{
seek_offset = offset;
return 0;
}
/* Read data from a file on the mmc device */
static int mmc_block_read(io_entity_t *entity, uintptr_t buffer,
size_t length, size_t *length_read)
{
*length_read = mmc_read_blocks(seek_offset / MMC_BLOCK_SIZE,
buffer, length);
if (*length_read != length) {
return -EIO;
}
return 0;
}
/* Close a file on the mmc device */
static int mmc_block_close(io_entity_t *entity)
{
return 0;
}
/* Register the mmc driver with the IO abstraction */
int register_io_dev_mmc(const io_dev_connector_t **dev_con)
{
int result;
assert(dev_con != NULL);
result = io_register_device(&mmc_dev_info);
if (result == 0) {
*dev_con = &mmc_dev_connector;
}
return result;
}