Browse Source

add v2/driver/*

Signed-off-by: surenyi <surenyi82@163.com>
master
surenyi 6 years ago
parent
commit
005107afad
  1. 2
      packages/vsky/libdsp/config.bld
  2. 21
      packages/vsky/libdsp/driver/of/base.c
  3. 119
      packages/vsky/libdsp/driver/of/fdt.c
  4. 1
      packages/vsky/libdsp/driver/of/of_private.h
  5. 56
      packages/vsky/libdsp/inc/list.h
  6. 13
      packages/vsky/libdsp/inc/of.h
  7. 11
      packages/vsky/libdsp/lua/lualib/kit.c
  8. 13
      packages/vsky/libdsp/package.bld
  9. 62
      packages/vsky/libdsp/v2/driver/board.c
  10. 27
      packages/vsky/libdsp/v2/driver/cpu.c
  11. 26
      packages/vsky/libdsp/v2/driver/driver.c
  12. 7
      packages/vsky/libdsp/v2/driver/driver_private.h
  13. 7
      packages/vsky/libdsp/v2/inc/driver.h
  14. 13
      packages/vsky/libdsp/v2/uapi/board.h

2
packages/vsky/libdsp/config.bld

@ -7,7 +7,7 @@ C66P.rootDir = toolsDir
/* include path */
var libdspPath = "$(PKGROOT)/vsky/libdsp/";
var libdspPathInclude = " -i" + libdspPath + "/inc" + " -i" + libdspPath + "/spiffs/src" + " -i" + libdspPath + "/lua/5.3.5" + " -i" + libdspPath + "/libfdt"
var libdspPathInclude = " -i" + libdspPath + "/inc" + " -i" + libdspPath + "/spiffs/src" + " -i" + libdspPath + "/lua/5.3.5" + " -i" + libdspPath + "/libfdt" + " -i" + libdspPath + "/v2/inc"
var Pkg = xdc.useModule("xdc.bld.PackageContents");
Pkg.generatedFiles.$add("lib/");

21
packages/vsky/libdsp/driver/of/base.c

@ -758,3 +758,24 @@ int of_property_read_variable_u16_array(const struct device_node *np, const char
return sz;
}
/** Checks if the device is compatible with any of the entries in
* a NULL terminated array of strings. Returns the best match
* score or 0.
*/
int of_device_compatible_match(struct device_node *device, const char *const *compat)
{
unsigned int tmp, score = 0;
if (!compat)
return 0;
while (*compat) {
tmp = of_device_is_compatible(device, *compat);
if (tmp > score)
score = tmp;
compat++;
}
return score;
}

119
packages/vsky/libdsp/driver/of/fdt.c

@ -438,3 +438,122 @@ const char * of_fdt_get_machine_name(void *mempos)
return name;
}
/**
* of_fdt_is_big_endian - Return true if given node needs BE MMIO accesses
* @blob: A device tree blob
* @node: node to test
*
* Returns true if the node has a "big-endian" property, or if the kernel
* was compiled for BE *and* the node has a "native-endian" property.
* Returns false otherwise.
*/
int of_fdt_is_big_endian(const void *blob, unsigned long node)
{
if (fdt_getprop(blob, node, "big-endian", NULL))
return 1;
#ifdef _LITTLE_ENDIAN
#else
if (fdt_getprop(blob, node, "native-endian", NULL))
return 1;
#endif
return 0;
}
/**
* of_fdt_is_compatible - Return true if given node from the given blob has
* compat in its compatible list
* @blob: A device tree blob
* @node: node to test
* @compat: compatible string to compare with compatible list.
*
* On match, returns a non-zero value with smaller values returned for more
* specific compatible values.
*/
int of_fdt_is_compatible(const void *blob, unsigned long node, const char *compat)
{
const char *cp;
int cplen;
unsigned long l, score = 0;
cp = fdt_getprop(blob, node, "compatible", &cplen);
if (cp == NULL)
return 0;
while (cplen > 0) {
score++;
if (strcasecmp(cp, compat) == 0)
return score;
l = strlen(cp) + 1;
cp += l;
cplen -= l;
}
return 0;
}
/**
* of_fdt_match - Return true if node matches a list of compatible values
*/
int of_fdt_match(const void *blob, unsigned long node, const char *const *compat)
{
unsigned int tmp, score = 0;
if (!compat)
return 0;
while (*compat) {
tmp = of_fdt_is_compatible(blob, node, *compat);
if (tmp && (score == 0 || (tmp < score)))
score = tmp;
compat++;
}
return score;
}
/**
* of_flat_dt_match_machine - Iterate match tables to find matching machine.
*
* @default_match: A machine specific ptr to return in case of no match.
* @get_next_compat: callback function to return next compatible match table.
*
* Iterate through machine match tables to find the best match for the machine
* compatible string in the FDT.
*/
const void * of_flat_dt_match_machine(void *mempos, const void *default_match, const void * (*get_next_compat)(const char * const**))
{
const void *data = NULL;
const void *best_data = default_match;
unsigned long dt_root;
const char *const *compat;
unsigned int best_score = ~1, score = 0;
while ((data = get_next_compat(&compat))) {
score = of_fdt_match(mempos, dt_root, compat);
if (score > 0 && score < best_score) {
best_data = data;
best_score = score;
}
}
if (!best_data) {
const char *prop;
int size;
printf("\n unrecognized device tree list:\n[ ");
prop = fdt_getprop(mempos, dt_root, "compatible", &size);
if (prop) {
while (size > 0) {
printf("'%s' ", prop);
size -= strlen(prop) + 1;
prop += strlen(prop) + 1;
}
}
printf("]\n\n");
return NULL;
}
printf("Machine model: %s\n", of_fdt_get_machine_name(mempos));
return best_data;
}

1
packages/vsky/libdsp/driver/of/of_private.h

@ -10,7 +10,6 @@ struct alias_prop {
char stem[0];
};
extern struct device_node *of_root;
extern struct device_node *of_aliases;
extern struct device_node *of_chosen;
extern struct device_node *of_stdout;

56
packages/vsky/libdsp/inc/list.h

@ -1,5 +1,6 @@
#ifndef __LIST_H____
#define __LIST_H____
#include <stddef.h>
struct list_head {
struct list_head *next, *prev;
@ -37,10 +38,65 @@ static inline void __list_add(struct list_head *_new,
prev->next = _new;
}
static inline void list_add(struct list_head *new, struct list_head *head)
{
__list_add(new, head, head->next);
}
static inline void list_add_tail(struct list_head *new, struct list_head *head)
{
__list_add(new, head->prev, head);
}
static inline void __list_del(struct list_head * prev, struct list_head * next)
{
next->prev = prev;
prev->next = next;
}
static inline void list_del(struct list_head *entry)
{
__list_del(entry->prev, entry->next);
entry->next = NULL;
entry->prev = NULL;
}
/**
* list_for_each - iterate over a list
* @pos: the &struct list_head to use as a loop cursor.
* @head: the head for your list.
*/
#define list_for_each(pos, head) \
for (pos = (head)->next; pos != (head); pos = pos->next)
/**
* list_for_each_prev - iterate over a list backwards
* @pos: the &struct list_head to use as a loop cursor.
* @head: the head for your list.
*/
#define list_for_each_prev(pos, head) \
for (pos = (head)->prev; pos != (head); pos = pos->prev)
/**
* list_for_each_safe - iterate over a list safe against removal of list entry
* @pos: the &struct list_head to use as a loop cursor.
* @n: another &struct list_head to use as temporary storage
* @head: the head for your list.
*/
#define list_for_each_safe(pos, n, head) \
for (pos = (head)->next, n = pos->next; pos != (head); \
pos = n, n = pos->next)
/**
* list_for_each_prev_safe - iterate over a list backwards safe against removal of list entry
* @pos: the &struct list_head to use as a loop cursor.
* @n: another &struct list_head to use as temporary storage
* @head: the head for your list.
*/
#define list_for_each_prev_safe(pos, n, head) \
for (pos = (head)->prev, n = pos->prev; \
pos != (head); \
pos = n, n = pos->prev)
#endif

13
packages/vsky/libdsp/inc/of.h

@ -1,6 +1,9 @@
#ifndef __DRIVER_OF_H__
#define __DRIVER_OF_H__
#include <stddef.h>
#include <stdint.h>
struct resource {
size_t start;
size_t end;
@ -85,6 +88,8 @@ struct device_node {
struct property *deadprops; /* removed properties */
};
extern struct device_node *of_root;
#define OF_ROOT_NODE_ADDR_CELLS_DEFAULT 1
#define OF_ROOT_NODE_SIZE_CELLS_DEFAULT 1
@ -325,9 +330,15 @@ const void *of_get_property(const struct device_node *np, const char *name, int
struct device_node *of_find_node_opts_by_path(const char *path, const char **opts);
void of_alias_scan(void * (*dt_alloc)(uint32_t size, uint32_t align));
/* fdt functions */
int of_fdt_is_compatible(const void *blob, unsigned long node, const char *compat);
int of_fdt_match(const void *blob, unsigned long node, const char *const *compat);
int of_fdt_is_big_endian(const void *blob, unsigned long node);
const void * of_flat_dt_match_machine(void *mempos, const void *default_match, const void * (*get_next_compat)(const char * const**));
void of_alias_scan(void * (*dt_alloc)(uint32_t size, uint32_t align));
struct device_node *of_get_next_parent(struct device_node *node);
int of_device_compatible_match(struct device_node *device, const char *const *compat);
int unflatten_device_tree(void *mempos);
const char * of_fdt_get_machine_name(void *mempos);

11
packages/vsky/libdsp/lua/lualib/kit.c

@ -560,7 +560,18 @@ static int __powerup(lua_State *L)
return 1;
}
extern int board_init(unsigned int);
static int __board_init(lua_State *L)
{
unsigned int dtb = luaL_checkinteger(L, 1);
int r;
r = board_init(dtb);
lua_pushboolean(L, r == 0);
return 1;
}
static struct luaL_Reg board[] = {
{"init", __board_init},
{"flash", __flash_open},
{"uart", __uart_open},
{"power", __powerup},

13
packages/vsky/libdsp/package.bld

@ -45,15 +45,10 @@ var drvFiles = [
"driver/of/address.c",
];
var emacFiles = [
"resource/resource_mgr.c",
"resource/osal.c",
"srio/srio_device.c",
"srio/srio_func.c",
"emac/nimu_eth.c",
"hyplnk/hyplnk_device.c",
"hyplnk/hyplnk_func.c",
"hyplnk/hyplnk_intr.c"
var v2Files = [
"v2/driver/driver.c",
"v2/driver/cpu.c",
"v2/driver/board.c",
];
var hispeedFiles = [

62
packages/vsky/libdsp/v2/driver/board.c

@ -0,0 +1,62 @@
#include <stdio.h>
#include "driver.h"
#include "driver_private.h"
#include "board.h"
static const char * const __boards[] = {
"c66x,c6678",
NULL,
};
static struct device __root = {
NULL, NULL, NULL, NULL, 0, NULL
};
void scan_devices(struct device_node *dn, struct device *parent, struct device *sibling)
{
struct driver *drv = NULL;
struct device *dev;
if (!root) {
return;
}
if (dn->full_name) {
printf("%s", dn->full_name);
}
if (dn->name) {
printf(" |%s\n", dn->name);
drv = driver_find(dn->name);
if (drv) {
dev = malloc(sizeof *dev + drv->extra_size);
if (dev) {
dev->parent = parent;
dev->sibling = sibling;
} else {
printf("%s: out of memory.\n", dn->name);
}
}
} else {
printf("\n");
}
scan_devices(dn->sibling);
scan_devices(dn->child);
}
int board_init(unsigned int dtb)
{
if (unflatten_device_tree((void *)dtb)) {
printf("unflatten device tree failed\n");
return -1;
}
if (!of_device_compatible_match(of_root, __boards)) {
printf("device tree is not for me.\n");
// return -2;
}
/* scan driver */
scan_devices(of_root, &__root, NULL);
return 0;
}

27
packages/vsky/libdsp/v2/driver/cpu.c

@ -0,0 +1,27 @@
#include "driver.h"
static int __attach(struct driver *drv, struct device_node *node)
{
return 0;
}
static int __active(struct device *dev)
{
return 0;
}
static int __deattach(struct device *dev)
{
return 0;
}
struct driver __cpu = {
"cpu",
__attach,
__active,
__deattach,
NULL,
0,
};

26
packages/vsky/libdsp/v2/driver/driver.c

@ -0,0 +1,26 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "driver.h"
#include "driver_private.h"
struct driver * __drivers[] = {
&__cpu,
NULL
};
struct driver *driver_find(const char *name)
{
int i = 0;
struct driver *dp;
while (__drivers[i]) {
dp = __drivers[i];
if (strcmp(dp->name, name) == 0) {
return dp;
}
++i;
}
return NULL;
}

7
packages/vsky/libdsp/v2/driver/driver_private.h

@ -0,0 +1,7 @@
#ifndef __DRIVER_PRIVATE_H__
#define __DRIVER_PRIVATE_H__
extern struct driver __cpu;
#endif

7
packages/vsky/libdsp/v2/inc/driver.h

@ -7,12 +7,14 @@ extern "C" {
#include "of.h"
struct driver;
struct device_node;
struct device {
struct driver *driver;
struct device *parent;
struct device *child;
struct device *slibing;
struct device_node *node;
int id;
void *extra;
};
@ -29,14 +31,17 @@ struct driver {
const char *name;
int (*attach)(struct driver *, struct device_node *);
int (*active)(struct device *);
int (*deattach)(struct device *);
struct file_operations *fop;
int extra_size;
/* private fields */
struct list_head next;
int count;
};
struct driver *driver_find(const char *name);
#ifdef __cplusplus
}
#endif
#endif

13
packages/vsky/libdsp/v2/uapi/board.h

@ -0,0 +1,13 @@
#ifndef __BOARD_H__
#define __BOARD_H__
#ifdef __cplusplus
extern "C" {
#endif
int board_init(unsigned int dtb);
#ifdef __cplusplus
}
#endif
#endif
Loading…
Cancel
Save