2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2015-09-17 20:42:40 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2015
|
2023-11-01 20:56:03 +00:00
|
|
|
* Texas Instruments Incorporated - https://www.ti.com/
|
2015-09-17 20:42:40 +00:00
|
|
|
*/
|
|
|
|
#define pr_fmt(fmt) "%s: " fmt, __func__
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <errno.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2015-09-17 20:42:40 +00:00
|
|
|
#include <remoteproc.h>
|
2019-05-31 13:11:33 +00:00
|
|
|
#include <asm/io.h>
|
2023-09-15 00:21:46 +00:00
|
|
|
#include <linux/printk.h>
|
2015-09-17 20:42:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* enum sandbox_state - different device states
|
|
|
|
* @sb_booted: Entry condition, just booted
|
|
|
|
* @sb_init: Initialized (basic environment is ready)
|
|
|
|
* @sb_reset: Held in reset (accessible, but not running)
|
|
|
|
* @sb_loaded: Loaded with image (but not running)
|
|
|
|
* @sb_running: Processor is running
|
|
|
|
*/
|
|
|
|
enum sandbox_state {
|
|
|
|
sb_booted,
|
|
|
|
sb_init,
|
|
|
|
sb_reset,
|
|
|
|
sb_loaded,
|
|
|
|
sb_running
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct sandbox_test_devdata - private data per device
|
|
|
|
* @current_state: device current state
|
|
|
|
*/
|
|
|
|
struct sandbox_test_devdata {
|
|
|
|
enum sandbox_state current_state;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sandbox_dev_move_to_state() - statemachine for our dummy device
|
|
|
|
* @dev: device to switch state
|
|
|
|
* @next_state: next proposed state
|
|
|
|
*
|
|
|
|
* This tries to follow the following statemachine:
|
|
|
|
* Entry
|
|
|
|
* |
|
|
|
|
* v
|
|
|
|
* +-------+
|
|
|
|
* +---+ init |
|
|
|
|
* | | | <---------------------+
|
|
|
|
* | +-------+ |
|
|
|
|
* | |
|
|
|
|
* | |
|
|
|
|
* | +--------+ |
|
|
|
|
* Load| | reset | |
|
|
|
|
* | | | <----------+ |
|
|
|
|
* | +--------+ | |
|
|
|
|
* | |Load | |
|
|
|
|
* | | | |
|
|
|
|
* | +----v----+ reset | |
|
|
|
|
* +-> | | (opt) | |
|
|
|
|
* | Loaded +-----------+ |
|
|
|
|
* | | |
|
|
|
|
* +----+----+ |
|
|
|
|
* | Start |
|
|
|
|
* +---v-----+ (opt) |
|
|
|
|
* +->| Running | Stop |
|
|
|
|
* Ping +- | +--------------------+
|
|
|
|
* (opt) +---------+
|
|
|
|
*
|
|
|
|
* (is_running does not change state)
|
|
|
|
*
|
|
|
|
* Return: 0 when valid state transition is seen, else returns -EINVAL
|
|
|
|
*/
|
|
|
|
static int sandbox_dev_move_to_state(struct udevice *dev,
|
|
|
|
enum sandbox_state next_state)
|
|
|
|
{
|
|
|
|
struct sandbox_test_devdata *ddata = dev_get_priv(dev);
|
|
|
|
|
|
|
|
/* No state transition is OK */
|
|
|
|
if (ddata->current_state == next_state)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
debug("current_state=%d, next_state=%d\n", ddata->current_state,
|
|
|
|
next_state);
|
|
|
|
switch (ddata->current_state) {
|
|
|
|
case sb_booted:
|
|
|
|
if (next_state == sb_init)
|
|
|
|
goto ok_state;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sb_init:
|
|
|
|
if (next_state == sb_reset || next_state == sb_loaded)
|
|
|
|
goto ok_state;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sb_reset:
|
|
|
|
if (next_state == sb_loaded || next_state == sb_init)
|
|
|
|
goto ok_state;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sb_loaded:
|
|
|
|
if (next_state == sb_reset || next_state == sb_init ||
|
|
|
|
next_state == sb_running)
|
|
|
|
goto ok_state;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sb_running:
|
|
|
|
if (next_state == sb_reset || next_state == sb_init)
|
|
|
|
goto ok_state;
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
ok_state:
|
|
|
|
ddata->current_state = next_state;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sandbox_testproc_probe() - basic probe function
|
|
|
|
* @dev: test proc device that is being probed.
|
|
|
|
*
|
|
|
|
* Return: 0 if all went ok, else return appropriate error
|
|
|
|
*/
|
|
|
|
static int sandbox_testproc_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct dm_rproc_uclass_pdata *uc_pdata;
|
|
|
|
struct sandbox_test_devdata *ddata;
|
|
|
|
int ret;
|
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
uc_pdata = dev_get_uclass_plat(dev);
|
2015-09-17 20:42:40 +00:00
|
|
|
ddata = dev_get_priv(dev);
|
|
|
|
if (!ddata) {
|
|
|
|
debug("%s: platform private data missing\n", uc_pdata->name);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
ret = sandbox_dev_move_to_state(dev, sb_booted);
|
|
|
|
debug("%s: called(%d)\n", uc_pdata->name, ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sandbox_testproc_init() - Simple initialization function
|
|
|
|
* @dev: device to operate upon
|
|
|
|
*
|
|
|
|
* Return: 0 if all went ok, else return appropriate error
|
|
|
|
*/
|
|
|
|
static int sandbox_testproc_init(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct dm_rproc_uclass_pdata *uc_pdata;
|
|
|
|
int ret;
|
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
uc_pdata = dev_get_uclass_plat(dev);
|
2015-09-17 20:42:40 +00:00
|
|
|
|
|
|
|
ret = sandbox_dev_move_to_state(dev, sb_init);
|
|
|
|
|
|
|
|
debug("%s: called(%d)\n", uc_pdata->name, ret);
|
|
|
|
if (ret)
|
|
|
|
debug("%s init failed\n", uc_pdata->name);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sandbox_testproc_reset() - Reset the remote processor
|
|
|
|
* @dev: device to operate upon
|
|
|
|
*
|
|
|
|
* Return: 0 if all went ok, else return appropriate error
|
|
|
|
*/
|
|
|
|
static int sandbox_testproc_reset(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct dm_rproc_uclass_pdata *uc_pdata;
|
|
|
|
int ret;
|
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
uc_pdata = dev_get_uclass_plat(dev);
|
2015-09-17 20:42:40 +00:00
|
|
|
|
|
|
|
ret = sandbox_dev_move_to_state(dev, sb_reset);
|
|
|
|
|
|
|
|
debug("%s: called(%d)\n", uc_pdata->name, ret);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
debug("%s reset failed\n", uc_pdata->name);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sandbox_testproc_load() - (replace: short desc)
|
|
|
|
* @dev: device to operate upon
|
|
|
|
* @addr: Address of the binary image to load
|
|
|
|
* @size: Size (in bytes) of the binary image to load
|
|
|
|
*
|
|
|
|
* Return: 0 if all went ok, else return appropriate error
|
|
|
|
*/
|
|
|
|
static int sandbox_testproc_load(struct udevice *dev, ulong addr, ulong size)
|
|
|
|
{
|
|
|
|
struct dm_rproc_uclass_pdata *uc_pdata;
|
|
|
|
int ret;
|
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
uc_pdata = dev_get_uclass_plat(dev);
|
2015-09-17 20:42:40 +00:00
|
|
|
|
|
|
|
ret = sandbox_dev_move_to_state(dev, sb_loaded);
|
|
|
|
|
|
|
|
debug("%s: called(%d) Loading to %08lX %lu size\n",
|
|
|
|
uc_pdata->name, ret, addr, size);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
debug("%s load failed\n", uc_pdata->name);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sandbox_testproc_start() - Start the remote processor
|
|
|
|
* @dev: device to operate upon
|
|
|
|
*
|
|
|
|
* Return: 0 if all went ok, else return appropriate error
|
|
|
|
*/
|
|
|
|
static int sandbox_testproc_start(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct dm_rproc_uclass_pdata *uc_pdata;
|
|
|
|
int ret;
|
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
uc_pdata = dev_get_uclass_plat(dev);
|
2015-09-17 20:42:40 +00:00
|
|
|
|
|
|
|
ret = sandbox_dev_move_to_state(dev, sb_running);
|
|
|
|
|
|
|
|
debug("%s: called(%d)\n", uc_pdata->name, ret);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
debug("%s start failed\n", uc_pdata->name);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sandbox_testproc_stop() - Stop the remote processor
|
|
|
|
* @dev: device to operate upon
|
|
|
|
*
|
|
|
|
* Return: 0 if all went ok, else return appropriate error
|
|
|
|
*/
|
|
|
|
static int sandbox_testproc_stop(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct dm_rproc_uclass_pdata *uc_pdata;
|
|
|
|
int ret;
|
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
uc_pdata = dev_get_uclass_plat(dev);
|
2015-09-17 20:42:40 +00:00
|
|
|
|
|
|
|
ret = sandbox_dev_move_to_state(dev, sb_init);
|
|
|
|
|
|
|
|
debug("%s: called(%d)\n", uc_pdata->name, ret);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
debug("%s stop failed\n", uc_pdata->name);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sandbox_testproc_is_running() - Check if remote processor is running
|
|
|
|
* @dev: device to operate upon
|
|
|
|
*
|
|
|
|
* Return: 0 if running, 1 if not running
|
|
|
|
*/
|
|
|
|
static int sandbox_testproc_is_running(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct dm_rproc_uclass_pdata *uc_pdata;
|
|
|
|
struct sandbox_test_devdata *ddata;
|
|
|
|
int ret = 1;
|
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
uc_pdata = dev_get_uclass_plat(dev);
|
2015-09-17 20:42:40 +00:00
|
|
|
ddata = dev_get_priv(dev);
|
|
|
|
|
|
|
|
if (ddata->current_state == sb_running)
|
|
|
|
ret = 0;
|
|
|
|
debug("%s: called(%d)\n", uc_pdata->name, ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* sandbox_testproc_ping() - Try pinging remote processor
|
|
|
|
* @dev: device to operate upon
|
|
|
|
*
|
|
|
|
* Return: 0 if running, -EINVAL if not running
|
|
|
|
*/
|
|
|
|
static int sandbox_testproc_ping(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct dm_rproc_uclass_pdata *uc_pdata;
|
|
|
|
struct sandbox_test_devdata *ddata;
|
|
|
|
int ret;
|
|
|
|
|
2020-12-03 23:55:18 +00:00
|
|
|
uc_pdata = dev_get_uclass_plat(dev);
|
2015-09-17 20:42:40 +00:00
|
|
|
ddata = dev_get_priv(dev);
|
|
|
|
|
|
|
|
if (ddata->current_state == sb_running)
|
|
|
|
ret = 0;
|
|
|
|
else
|
|
|
|
ret = -EINVAL;
|
|
|
|
|
|
|
|
debug("%s: called(%d)\n", uc_pdata->name, ret);
|
|
|
|
if (ret)
|
|
|
|
debug("%s: No response.(Not started?)\n", uc_pdata->name);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-05-31 13:11:33 +00:00
|
|
|
#define SANDBOX_RPROC_DEV_TO_PHY_OFFSET 0x1000
|
|
|
|
/**
|
|
|
|
* sandbox_testproc_device_to_virt() - Convert device address to virtual address
|
|
|
|
* @dev: device to operate upon
|
|
|
|
* @da: device address
|
2019-09-04 10:31:27 +00:00
|
|
|
* @size: Size of the memory region @da is pointing to
|
2022-01-19 17:05:50 +00:00
|
|
|
* Return: converted virtual address
|
2019-05-31 13:11:33 +00:00
|
|
|
*/
|
2019-09-04 10:31:27 +00:00
|
|
|
static void *sandbox_testproc_device_to_virt(struct udevice *dev, ulong da,
|
|
|
|
ulong size)
|
2019-05-31 13:11:33 +00:00
|
|
|
{
|
|
|
|
u64 paddr;
|
|
|
|
|
|
|
|
/* Use a simple offset conversion */
|
|
|
|
paddr = da + SANDBOX_RPROC_DEV_TO_PHY_OFFSET;
|
|
|
|
|
|
|
|
return phys_to_virt(paddr);
|
|
|
|
}
|
|
|
|
|
2015-09-17 20:42:40 +00:00
|
|
|
static const struct dm_rproc_ops sandbox_testproc_ops = {
|
|
|
|
.init = sandbox_testproc_init,
|
|
|
|
.reset = sandbox_testproc_reset,
|
|
|
|
.load = sandbox_testproc_load,
|
|
|
|
.start = sandbox_testproc_start,
|
|
|
|
.stop = sandbox_testproc_stop,
|
|
|
|
.is_running = sandbox_testproc_is_running,
|
|
|
|
.ping = sandbox_testproc_ping,
|
2019-05-31 13:11:33 +00:00
|
|
|
.device_to_virt = sandbox_testproc_device_to_virt,
|
2015-09-17 20:42:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct udevice_id sandbox_ids[] = {
|
|
|
|
{.compatible = "sandbox,test-processor"},
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(sandbox_testproc) = {
|
|
|
|
.name = "sandbox_test_proc",
|
|
|
|
.of_match = sandbox_ids,
|
|
|
|
.id = UCLASS_REMOTEPROC,
|
|
|
|
.ops = &sandbox_testproc_ops,
|
|
|
|
.probe = sandbox_testproc_probe,
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct sandbox_test_devdata),
|
2015-09-17 20:42:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* TODO(nm@ti.com): Remove this along with non-DT support */
|
|
|
|
static struct dm_rproc_uclass_pdata proc_3_test = {
|
|
|
|
.name = "proc_3_legacy",
|
|
|
|
.mem_type = RPROC_INTERNAL_MEMORY_MAPPED,
|
|
|
|
};
|
|
|
|
|
2020-12-29 03:34:54 +00:00
|
|
|
U_BOOT_DRVINFO(proc_3_demo) = {
|
2015-09-17 20:42:40 +00:00
|
|
|
.name = "sandbox_test_proc",
|
2020-12-03 23:55:18 +00:00
|
|
|
.plat = &proc_3_test,
|
2015-09-17 20:42:40 +00:00
|
|
|
};
|