Skip to content

Commit

Permalink
Merge pull request #45 from zevweiss/bunch-o-stuff
Browse files Browse the repository at this point in the history
Bridge disabling, wdt fixes, etc.

Signed-off-by: Andrew Jeffery <[email protected]>
  • Loading branch information
amboar authored Feb 14, 2024
2 parents b919da2 + bad6768 commit 9e29560
Show file tree
Hide file tree
Showing 16 changed files with 272 additions and 125 deletions.
18 changes: 10 additions & 8 deletions src/ahb.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@
#include <string.h>
#include <unistd.h>

const char *ahb_interface_names[ahb_max_interfaces] = {
[ahb_ilpcb] = "iLPC2AHB",
[ahb_l2ab] = "LPC2AHB",
[ahb_p2ab] = "P2A",
[ahb_debug] = "Debug UART",
[ahb_devmem] = "devmem",
};

#define AHB_CHUNK (1 << 20)

ssize_t ahb_siphon_in(struct ahb *ctx, uint32_t phys, size_t len, int outfd)
Expand Down Expand Up @@ -91,3 +83,13 @@ ssize_t ahb_siphon_out(struct ahb *ctx, uint32_t phys, int infd)

return rc;
}

int ahb_release_bridge(struct ahb *ctx)
{
return ctx->drv->release ? ctx->drv->release(ctx) : 0;
}

int ahb_reinit_bridge(struct ahb *ctx)
{
return ctx->drv->reinit ? ctx->drv->reinit(ctx) : 0;
}
22 changes: 8 additions & 14 deletions src/ahb.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,14 @@
#define _AHB_H

#include "log.h"
#include "bridge.h"

#include <inttypes.h>
#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>
#include <sys/types.h>

enum ahb_bridge {
ahb_ilpcb,
ahb_l2ab,
ahb_p2ab,
ahb_debug,
ahb_devmem,
ahb_max_interfaces
};

extern const char *ahb_interface_names[ahb_max_interfaces];

struct ahb_range {
const char *name;
uint32_t start;
Expand All @@ -40,13 +30,14 @@ struct ahb_ops {
};

struct ahb {
enum ahb_bridge type;
const struct bridge_driver *drv;
const struct ahb_ops *ops;
};

static inline void ahb_init_ops(struct ahb *ctx, enum ahb_bridge type, const struct ahb_ops *ops)
static inline void ahb_init_ops(struct ahb *ctx, const struct bridge_driver *drv,
const struct ahb_ops *ops)
{
ctx->type = type;
ctx->drv = drv;
ctx->ops = ops;
}

Expand Down Expand Up @@ -84,4 +75,7 @@ static inline int ahb_writel(struct ahb *ctx, uint32_t phys, uint32_t val)
ssize_t ahb_siphon_in(struct ahb *ctx, uint32_t phys, size_t len, int outfd);
ssize_t ahb_siphon_out(struct ahb *ctx, uint32_t phys, int infd);

int ahb_release_bridge(struct ahb *ctx);
int ahb_reinit_bridge(struct ahb *ctx);

#endif
14 changes: 13 additions & 1 deletion src/bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,27 @@
#ifndef _BRIDGE_H
#define _BRIDGE_H

#include <stdbool.h>

#include "ahb.h"

#include "ccan/autodata/autodata.h"

struct bridge_driver {
enum ahb_bridge type;
const char *name;
struct ahb *(*probe)(int argc, char *argv[]);
int (*release)(struct ahb *ahb);
int (*reinit)(struct ahb *ahb);
void (*destroy)(struct ahb *ahb);

/*
* Whether or not this driver is for running culvert on the BMC itself
* (i.e. devmem)
*/
bool local;

/* Set if this driver has been explicitly disabled */
bool disabled;
};

AUTODATA_TYPE(bridge_drivers, struct bridge_driver);
Expand Down
37 changes: 29 additions & 8 deletions src/bridge/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ int debug_probe(struct debug *ctx)
{
int rc;

logd("Probing %s\n", ahb_interface_names[ahb_debug]);
logd("Probing %s\n", ctx->ahb.drv->name);

rc = debug_enter(ctx);
if (rc < 0)
Expand Down Expand Up @@ -445,6 +445,20 @@ static const struct ahb_ops debug_ahb_ops = {
.writel = debug_writel
};

static struct ahb *debug_driver_probe(int argc, char *argv[]);
static void debug_driver_destroy(struct ahb *ahb);
static int debug_driver_release(struct ahb *ahb);
static int debug_driver_reinit(struct ahb *ahb);

static struct bridge_driver debug_driver = {
.name = "debug-uart",
.probe = debug_driver_probe,
.destroy = debug_driver_destroy,
.release = debug_driver_release,
.reinit = debug_driver_reinit,
};
REGISTER_BRIDGE_DRIVER(debug_driver);

int debug_init_v(struct debug *ctx, va_list args)
{
const char *interface;
Expand Down Expand Up @@ -478,7 +492,7 @@ int debug_init_v(struct debug *ctx, va_list args)
rc = prompt_init(&ctx->prompt, fd, "\r", false);
if (rc < 0) { goto cleanup_ts16; }

ahb_init_ops(&ctx->ahb, ahb_debug, &debug_ahb_ops);
ahb_init_ops(&ctx->ahb, &debug_driver, &debug_ahb_ops);

return 0;

Expand Down Expand Up @@ -560,9 +574,16 @@ static void debug_driver_destroy(struct ahb *ahb)
free(ctx);
}

static const struct bridge_driver debug_driver = {
.type = ahb_debug,
.probe = debug_driver_probe,
.destroy = debug_driver_destroy,
};
REGISTER_BRIDGE_DRIVER(debug_driver);
static int debug_driver_release(struct ahb *ahb)
{
struct debug *ctx = to_debug(ahb);

return debug_exit(ctx);
}

static int debug_driver_reinit(struct ahb *ahb)
{
struct debug *ctx = to_debug(ahb);

return debug_enter(ctx);
}
22 changes: 13 additions & 9 deletions src/bridge/devmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ int devmem_probe(struct devmem *ctx)
{
int rc;

logd("Probing %s\n", ahb_interface_names[ahb_devmem]);
logd("Probing %s\n", ctx->ahb.drv->name);

#ifndef __arm__
return -ENOTSUP;
Expand Down Expand Up @@ -166,6 +166,17 @@ static const struct ahb_ops devmem_ahb_ops = {
.writel = devmem_writel
};

static struct ahb *devmem_driver_probe(int argc, char *argv[]);
static void devmem_driver_destroy(struct ahb *ahb);

static struct bridge_driver devmem_driver = {
.name = "devmem",
.probe = devmem_driver_probe,
.destroy = devmem_driver_destroy,
.local = true,
};
REGISTER_BRIDGE_DRIVER(devmem_driver);

int devmem_init(struct devmem *ctx)
{
int cleanup;
Expand All @@ -183,7 +194,7 @@ int devmem_init(struct devmem *ctx)

ctx->win = NULL;

ahb_init_ops(&ctx->ahb, ahb_devmem, &devmem_ahb_ops);
ahb_init_ops(&ctx->ahb, &devmem_driver, &devmem_ahb_ops);

return 0;

Expand Down Expand Up @@ -257,10 +268,3 @@ static void devmem_driver_destroy(struct ahb *ahb)

free(ctx);
}

static const struct bridge_driver devmem_driver = {
.type = ahb_devmem,
.probe = devmem_driver_probe,
.destroy = devmem_driver_destroy,
};
REGISTER_BRIDGE_DRIVER(devmem_driver);
21 changes: 12 additions & 9 deletions src/bridge/ilpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int ilpcb_probe(struct ilpcb *ctx)
{
int rc;

logd("Probing %s\n", ahb_interface_names[ahb_ilpcb]);
logd("Probing %s\n", ctx->ahb.drv->name);

if (!sio_probe(&ctx->sio))
return 0;
Expand Down Expand Up @@ -308,9 +308,19 @@ static const struct ahb_ops ilpcb_ops = {
.writel = ilpcb_writel
};

static struct ahb *ilpcb_driver_probe(int argc, char *argv[]);
static void ilpcb_driver_destroy(struct ahb *ahb);

static struct bridge_driver ilpcb_driver = {
.name = "ilpc",
.probe = ilpcb_driver_probe,
.destroy = ilpcb_driver_destroy,
};
REGISTER_BRIDGE_DRIVER(ilpcb_driver);

int ilpcb_init(struct ilpcb *ctx)
{
ahb_init_ops(&ctx->ahb, ahb_ilpcb, &ilpcb_ops);
ahb_init_ops(&ctx->ahb, &ilpcb_driver, &ilpcb_ops);

return sio_init(&ctx->sio);
}
Expand Down Expand Up @@ -368,10 +378,3 @@ static void ilpcb_driver_destroy(struct ahb *ahb)

free(ctx);
}

static const struct bridge_driver ilpcb_driver = {
.type = ahb_ilpcb,
.probe = ilpcb_driver_probe,
.destroy = ilpcb_driver_destroy,
};
REGISTER_BRIDGE_DRIVER(ilpcb_driver);
68 changes: 50 additions & 18 deletions src/bridge/l2a.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,44 @@ static const struct ahb_ops l2ab_ahb_ops = {
.writel = l2ab_writel,
};

static int l2ab_save_hicr78(struct l2ab *ctx)
{
struct ilpcb *ilpcb = &ctx->ilpcb;
int rc;

rc = ilpcb_readl(ilpcb_as_ahb(ilpcb), LPC_HICR7, &ctx->restore7);
if (rc)
return rc;

return ilpcb_readl(ilpcb_as_ahb(ilpcb), LPC_HICR8, &ctx->restore8);
}

static int l2ab_restore_hicr78(struct l2ab *ctx)
{
struct ilpcb *ilpcb = &ctx->ilpcb;
int rc;

rc = ilpcb_writel(ilpcb_as_ahb(ilpcb), LPC_HICR8, ctx->restore8);
if (rc)
return rc;

return ilpcb_writel(ilpcb_as_ahb(ilpcb), LPC_HICR7, ctx->restore7);
}

static struct ahb *l2ab_driver_probe(int argc, char *argv[]);
static void l2ab_driver_destroy(struct ahb *ahb);
static int l2ab_driver_release(struct ahb *ahb);
static int l2ab_driver_reinit(struct ahb *ahb);

static struct bridge_driver l2ab_driver = {
.name = "l2a",
.probe = l2ab_driver_probe,
.destroy = l2ab_driver_destroy,
.reinit = l2ab_driver_reinit,
.release = l2ab_driver_release,
};
REGISTER_BRIDGE_DRIVER(l2ab_driver);

int l2ab_init(struct l2ab *ctx)
{
struct ilpcb *ilpcb = &ctx->ilpcb;
Expand All @@ -154,15 +192,11 @@ int l2ab_init(struct l2ab *ctx)
if (rc)
goto cleanup;

rc = ilpcb_readl(ilpcb_as_ahb(ilpcb), LPC_HICR7, &ctx->restore7);
rc = l2ab_save_hicr78(ctx);
if (rc)
goto cleanup;

rc = ilpcb_readl(ilpcb_as_ahb(ilpcb), LPC_HICR8, &ctx->restore8);
if (rc)
goto cleanup;

ahb_init_ops(&ctx->ahb, ahb_l2ab, &l2ab_ahb_ops);
ahb_init_ops(&ctx->ahb, &l2ab_driver, &l2ab_ahb_ops);

return 0;

Expand All @@ -175,14 +209,9 @@ int l2ab_init(struct l2ab *ctx)

int l2ab_destroy(struct l2ab *ctx)
{
struct ilpcb *ilpcb = &ctx->ilpcb;
int rc;

rc = ilpcb_writel(ilpcb_as_ahb(ilpcb), LPC_HICR8, ctx->restore8);
if (rc)
return rc;

rc = ilpcb_writel(ilpcb_as_ahb(ilpcb), LPC_HICR7, ctx->restore7);
rc = l2ab_restore_hicr78(ctx);
if (rc)
return rc;

Expand Down Expand Up @@ -234,9 +263,12 @@ static void l2ab_driver_destroy(struct ahb *ahb)
free(ctx);
}

static const struct bridge_driver l2ab_driver = {
.type = ahb_l2ab,
.probe = l2ab_driver_probe,
.destroy = l2ab_driver_destroy,
};
REGISTER_BRIDGE_DRIVER(l2ab_driver);
static int l2ab_driver_release(struct ahb *ahb)
{
return l2ab_restore_hicr78(to_l2ab(ahb));
}

static int l2ab_driver_reinit(struct ahb *ahb)
{
return l2ab_save_hicr78(to_l2ab(ahb));
}
Loading

0 comments on commit 9e29560

Please sign in to comment.