Commit 43fdf274 authored by David S. Miller's avatar David S. Miller

[SPARC64]: Abstract out mdesc accesses for better MD update handling.

Since we have to be able to handle MD updates, having an in-tree
set of data structures representing the MD objects actually makes
things more painful.

The MD itself is easy to parse, and we can implement the existing
interfaces using direct parsing of the MD binary image.

The MD is now reference counted, so accesses have to now take the
form:

	handle = mdesc_grab();

	... operations on MD ...

	mdesc_release(handle);

The only remaining issue are cases where code holds on to references
to MD property values.  mdesc_get_property() returns a direct pointer
to the property value, most cases just pull in the information they
need and discard the pointer, but there are few that use the pointer
directly over a long lifetime.  Those will be fixed up in a subsequent
changeset.

A preliminary handler for MD update events from domain services is
there, it is rudimentry but it works and handles all of the reference
counting.  It does not check the generation number of the MDs,
and it does not generate a "add/delete" list for notification to
interesting parties about MD changes but that will be forthcoming.
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 133f09a1
......@@ -15,6 +15,7 @@
#include <asm/ldc.h>
#include <asm/vio.h>
#include <asm/power.h>
#include <asm/mdesc.h>
#define DRV_MODULE_NAME "ds"
#define PFX DRV_MODULE_NAME ": "
......@@ -170,8 +171,7 @@ static void md_update_data(struct ldc_channel *lp,
rp = (struct ds_md_update_req *) (dpkt + 1);
printk(KERN_ERR PFX "MD update REQ [%lx] len=%d\n",
rp->req_num, len);
printk(KERN_ERR PFX "Machine description update.\n");
memset(&pkt, 0, sizeof(pkt));
pkt.data.tag.type = DS_DATA;
......@@ -181,6 +181,8 @@ static void md_update_data(struct ldc_channel *lp,
pkt.res.result = DS_OK;
ds_send(lp, &pkt, sizeof(pkt));
mdesc_update();
}
struct ds_shutdown_req {
......@@ -555,7 +557,6 @@ static int __devinit ds_probe(struct vio_dev *vdev,
const struct vio_device_id *id)
{
static int ds_version_printed;
struct mdesc_node *endp;
struct ldc_channel_config ds_cfg = {
.event = ds_event,
.mtu = 4096,
......@@ -563,20 +564,11 @@ static int __devinit ds_probe(struct vio_dev *vdev,
};
struct ldc_channel *lp;
struct ds_info *dp;
const u64 *chan_id;
int err;
if (ds_version_printed++ == 0)
printk(KERN_INFO "%s", version);
endp = vio_find_endpoint(vdev);
if (!endp)
return -ENODEV;
chan_id = md_get_property(endp, "id", NULL);
if (!chan_id)
return -ENODEV;
dp = kzalloc(sizeof(*dp), GFP_KERNEL);
err = -ENOMEM;
if (!dp)
......@@ -588,10 +580,10 @@ static int __devinit ds_probe(struct vio_dev *vdev,
dp->rcv_buf_len = 4096;
ds_cfg.tx_irq = endp->irqs[0];
ds_cfg.rx_irq = endp->irqs[1];
ds_cfg.tx_irq = vdev->tx_irq;
ds_cfg.rx_irq = vdev->rx_irq;
lp = ldc_alloc(*chan_id, &ds_cfg, dp);
lp = ldc_alloc(vdev->channel_id, &ds_cfg, dp);
if (IS_ERR(lp)) {
err = PTR_ERR(lp);
goto out_free_rcv_buf;
......
......@@ -2335,15 +2335,20 @@ EXPORT_SYMBOL(ldc_free_exp_dring);
static int __init ldc_init(void)
{
struct mdesc_node *mp;
unsigned long major, minor;
struct mdesc_handle *hp;
const u64 *v;
u64 mp;
mp = md_find_node_by_name(NULL, "platform");
if (!mp)
hp = mdesc_grab();
if (!hp)
return -ENODEV;
v = md_get_property(mp, "domaining-enabled", NULL);
mp = mdesc_node_by_name(hp, MDESC_NODE_NULL, "platform");
if (mp == MDESC_NODE_NULL)
return -ENODEV;
v = mdesc_get_property(hp, mp, "domaining-enabled", NULL);
if (!v)
return -ENODEV;
......
......@@ -6,6 +6,8 @@
#include <linux/types.h>
#include <linux/bootmem.h>
#include <linux/log2.h>
#include <linux/list.h>
#include <linux/slab.h>
#include <asm/hypervisor.h>
#include <asm/mdesc.h>
......@@ -29,7 +31,7 @@ struct mdesc_hdr {
u32 node_sz; /* node block size */
u32 name_sz; /* name block size */
u32 data_sz; /* data block size */
};
} __attribute__((aligned(16)));
struct mdesc_elem {
u8 tag;
......@@ -53,306 +55,386 @@ struct mdesc_elem {
} d;
};
static struct mdesc_hdr *main_mdesc;
static struct mdesc_node *allnodes;
static struct mdesc_node *allnodes_tail;
static unsigned int unique_id;
struct mdesc_mem_ops {
struct mdesc_handle *(*alloc)(unsigned int mdesc_size);
void (*free)(struct mdesc_handle *handle);
};
static struct mdesc_node **mdesc_hash;
static unsigned int mdesc_hash_size;
struct mdesc_handle {
struct list_head list;
struct mdesc_mem_ops *mops;
void *self_base;
atomic_t refcnt;
unsigned int handle_size;
struct mdesc_hdr mdesc;
};
static inline unsigned int node_hashfn(u64 node)
static void mdesc_handle_init(struct mdesc_handle *hp,
unsigned int handle_size,
void *base)
{
return ((unsigned int) (node ^ (node >> 8) ^ (node >> 16)))
& (mdesc_hash_size - 1);
BUG_ON(((unsigned long)&hp->mdesc) & (16UL - 1));
memset(hp, 0, handle_size);
INIT_LIST_HEAD(&hp->list);
hp->self_base = base;
atomic_set(&hp->refcnt, 1);
hp->handle_size = handle_size;
}
static inline void hash_node(struct mdesc_node *mp)
static struct mdesc_handle *mdesc_bootmem_alloc(unsigned int mdesc_size)
{
struct mdesc_node **head = &mdesc_hash[node_hashfn(mp->node)];
struct mdesc_handle *hp;
unsigned int handle_size, alloc_size;
mp->hash_next = *head;
*head = mp;
handle_size = (sizeof(struct mdesc_handle) -
sizeof(struct mdesc_hdr) +
mdesc_size);
alloc_size = PAGE_ALIGN(handle_size);
if (allnodes_tail) {
allnodes_tail->allnodes_next = mp;
allnodes_tail = mp;
} else {
allnodes = allnodes_tail = mp;
}
hp = __alloc_bootmem(alloc_size, PAGE_SIZE, 0UL);
if (hp)
mdesc_handle_init(hp, handle_size, hp);
return hp;
}
static struct mdesc_node *find_node(u64 node)
static void mdesc_bootmem_free(struct mdesc_handle *hp)
{
struct mdesc_node *mp = mdesc_hash[node_hashfn(node)];
unsigned int alloc_size, handle_size = hp->handle_size;
unsigned long start, end;
while (mp) {
if (mp->node == node)
return mp;
BUG_ON(atomic_read(&hp->refcnt) != 0);
BUG_ON(!list_empty(&hp->list));
mp = mp->hash_next;
alloc_size = PAGE_ALIGN(handle_size);
start = (unsigned long) hp;
end = start + alloc_size;
while (start < end) {
struct page *p;
p = virt_to_page(start);
ClearPageReserved(p);
__free_page(p);
start += PAGE_SIZE;
}
return NULL;
}
struct property *md_find_property(const struct mdesc_node *mp,
const char *name,
int *lenp)
static struct mdesc_mem_ops bootmem_mdesc_memops = {
.alloc = mdesc_bootmem_alloc,
.free = mdesc_bootmem_free,
};
static struct mdesc_handle *mdesc_kmalloc(unsigned int mdesc_size)
{
struct property *pp;
unsigned int handle_size;
void *base;
for (pp = mp->properties; pp != 0; pp = pp->next) {
if (strcasecmp(pp->name, name) == 0) {
if (lenp)
*lenp = pp->length;
break;
}
handle_size = (sizeof(struct mdesc_handle) -
sizeof(struct mdesc_hdr) +
mdesc_size);
base = kmalloc(handle_size + 15, GFP_KERNEL);
if (base) {
struct mdesc_handle *hp;
unsigned long addr;
addr = (unsigned long)base;
addr = (addr + 15UL) & ~15UL;
hp = (struct mdesc_handle *) addr;
mdesc_handle_init(hp, handle_size, base);
return hp;
}
return pp;
return NULL;
}
EXPORT_SYMBOL(md_find_property);
/*
* Find a property with a given name for a given node
* and return the value.
*/
const void *md_get_property(const struct mdesc_node *mp, const char *name,
int *lenp)
static void mdesc_kfree(struct mdesc_handle *hp)
{
struct property *pp = md_find_property(mp, name, lenp);
return pp ? pp->value : NULL;
BUG_ON(atomic_read(&hp->refcnt) != 0);
BUG_ON(!list_empty(&hp->list));
kfree(hp->self_base);
}
EXPORT_SYMBOL(md_get_property);
struct mdesc_node *md_find_node_by_name(struct mdesc_node *from,
const char *name)
static struct mdesc_mem_ops kmalloc_mdesc_memops = {
.alloc = mdesc_kmalloc,
.free = mdesc_kfree,
};
static struct mdesc_handle *mdesc_alloc(unsigned int mdesc_size,
struct mdesc_mem_ops *mops)
{
struct mdesc_node *mp;
struct mdesc_handle *hp = mops->alloc(mdesc_size);
mp = from ? from->allnodes_next : allnodes;
for (; mp != NULL; mp = mp->allnodes_next) {
if (strcmp(mp->name, name) == 0)
break;
}
return mp;
}
EXPORT_SYMBOL(md_find_node_by_name);
if (hp)
hp->mops = mops;
static unsigned int mdesc_early_allocated;
return hp;
}
static void * __init mdesc_early_alloc(unsigned long size)
static void mdesc_free(struct mdesc_handle *hp)
{
void *ret;
hp->mops->free(hp);
}
ret = __alloc_bootmem(size, SMP_CACHE_BYTES, 0UL);
if (ret == NULL) {
prom_printf("MDESC: alloc of %lu bytes failed.\n", size);
prom_halt();
}
static struct mdesc_handle *cur_mdesc;
static LIST_HEAD(mdesc_zombie_list);
static DEFINE_SPINLOCK(mdesc_lock);
memset(ret, 0, size);
struct mdesc_handle *mdesc_grab(void)
{
struct mdesc_handle *hp;
unsigned long flags;
mdesc_early_allocated += size;
spin_lock_irqsave(&mdesc_lock, flags);
hp = cur_mdesc;
if (hp)
atomic_inc(&hp->refcnt);
spin_unlock_irqrestore(&mdesc_lock, flags);
return ret;
return hp;
}
EXPORT_SYMBOL(mdesc_grab);
static unsigned int __init count_arcs(struct mdesc_elem *ep)
void mdesc_release(struct mdesc_handle *hp)
{
unsigned int ret = 0;
unsigned long flags;
ep++;
while (ep->tag != MD_NODE_END) {
if (ep->tag == MD_PROP_ARC)
ret++;
ep++;
spin_lock_irqsave(&mdesc_lock, flags);
if (atomic_dec_and_test(&hp->refcnt)) {
list_del_init(&hp->list);
hp->mops->free(hp);
}
return ret;
spin_unlock_irqrestore(&mdesc_lock, flags);
}
EXPORT_SYMBOL(mdesc_release);
static void __init mdesc_node_alloc(u64 node, struct mdesc_elem *ep, const char *names)
static void do_mdesc_update(struct work_struct *work)
{
unsigned int num_arcs = count_arcs(ep);
struct mdesc_node *mp;
unsigned long len, real_len, status;
struct mdesc_handle *hp, *orig_hp;
unsigned long flags;
(void) sun4v_mach_desc(0UL, 0UL, &len);
hp = mdesc_alloc(len, &kmalloc_mdesc_memops);
if (!hp) {
printk(KERN_ERR "MD: mdesc alloc fails\n");
return;
}
status = sun4v_mach_desc(__pa(&hp->mdesc), len, &real_len);
if (status != HV_EOK || real_len > len) {
printk(KERN_ERR "MD: mdesc reread fails with %lu\n",
status);
atomic_dec(&hp->refcnt);
mdesc_free(hp);
return;
}
mp = mdesc_early_alloc(sizeof(*mp) +
(num_arcs * sizeof(struct mdesc_arc)));
mp->name = names + ep->name_offset;
mp->node = node;
mp->unique_id = unique_id++;
mp->num_arcs = num_arcs;
spin_lock_irqsave(&mdesc_lock, flags);
orig_hp = cur_mdesc;
cur_mdesc = hp;
hash_node(mp);
if (atomic_dec_and_test(&orig_hp->refcnt))
mdesc_free(orig_hp);
else
list_add(&orig_hp->list, &mdesc_zombie_list);
spin_unlock_irqrestore(&mdesc_lock, flags);
}
static inline struct mdesc_elem *node_block(struct mdesc_hdr *mdesc)
static DECLARE_WORK(mdesc_update_work, do_mdesc_update);
void mdesc_update(void)
{
schedule_work(&mdesc_update_work);
}
static struct mdesc_elem *node_block(struct mdesc_hdr *mdesc)
{
return (struct mdesc_elem *) (mdesc + 1);
}
static inline void *name_block(struct mdesc_hdr *mdesc)
static void *name_block(struct mdesc_hdr *mdesc)
{
return ((void *) node_block(mdesc)) + mdesc->node_sz;
}
static inline void *data_block(struct mdesc_hdr *mdesc)
static void *data_block(struct mdesc_hdr *mdesc)
{
return ((void *) name_block(mdesc)) + mdesc->name_sz;
}
/* In order to avoid recursion (the graph can be very deep) we use a
* two pass algorithm. First we allocate all the nodes and hash them.
* Then we iterate over each node, filling in the arcs and properties.
*/
static void __init build_all_nodes(struct mdesc_hdr *mdesc)
u64 mdesc_node_by_name(struct mdesc_handle *hp,
u64 from_node, const char *name)
{
struct mdesc_elem *start, *ep;
struct mdesc_node *mp;
const char *names;
void *data;
u64 last_node;
start = ep = node_block(mdesc);
last_node = mdesc->node_sz / 16;
struct mdesc_elem *ep = node_block(&hp->mdesc);
const char *names = name_block(&hp->mdesc);
u64 last_node = hp->mdesc.node_sz / 16;
u64 ret;
if (from_node == MDESC_NODE_NULL)
from_node = 0;
if (from_node >= last_node)
return MDESC_NODE_NULL;
ret = ep[from_node].d.val;
while (ret < last_node) {
if (ep[ret].tag != MD_NODE)
return MDESC_NODE_NULL;
if (!strcmp(names + ep[ret].name_offset, name))
break;
ret = ep[ret].d.val;
}
if (ret >= last_node)
ret = MDESC_NODE_NULL;
return ret;
}
EXPORT_SYMBOL(mdesc_node_by_name);
names = name_block(mdesc);
const void *mdesc_get_property(struct mdesc_handle *hp, u64 node,
const char *name, int *lenp)
{
const char *names = name_block(&hp->mdesc);
u64 last_node = hp->mdesc.node_sz / 16;
void *data = data_block(&hp->mdesc);
struct mdesc_elem *ep;
while (1) {
u64 node = ep - start;
if (node == MDESC_NODE_NULL || node >= last_node)
return NULL;
if (ep->tag == MD_LIST_END)
ep = node_block(&hp->mdesc) + node;
ep++;
for (; ep->tag != MD_NODE_END; ep++) {
void *val = NULL;
int len = 0;
switch (ep->tag) {
case MD_PROP_VAL:
val = &ep->d.val;
len = 8;
break;
if (ep->tag != MD_NODE) {
prom_printf("MDESC: Inconsistent element list.\n");
prom_halt();
}
mdesc_node_alloc(node, ep, names);
case MD_PROP_STR:
case MD_PROP_DATA:
val = data + ep->d.data.data_offset;
len = ep->d.data.data_len;
break;
if (ep->d.val >= last_node) {
printk("MDESC: Warning, early break out of node scan.\n");
printk("MDESC: Next node [%lu] last_node [%lu].\n",
node, last_node);
default:
break;
}
if (!val)
continue;
ep = start + ep->d.val;
if (!strcmp(names + ep->name_offset, name)) {
if (lenp)
*lenp = len;
return val;
}
}
data = data_block(mdesc);
for (mp = allnodes; mp; mp = mp->allnodes_next) {
struct mdesc_elem *ep = start + mp->node;
struct property **link = &mp->properties;
unsigned int this_arc = 0;
ep++;
while (ep->tag != MD_NODE_END) {
switch (ep->tag) {
case MD_PROP_ARC: {
struct mdesc_node *target;
if (this_arc >= mp->num_arcs) {
prom_printf("MDESC: ARC overrun [%u:%u]\n",
this_arc, mp->num_arcs);
prom_halt();
}
target = find_node(ep->d.val);
if (!target) {
printk("MDESC: Warning, arc points to "
"missing node, ignoring.\n");
break;
}
mp->arcs[this_arc].name =
(names + ep->name_offset);
mp->arcs[this_arc].arc = target;
this_arc++;
break;
}
return NULL;
}
EXPORT_SYMBOL(mdesc_get_property);
case MD_PROP_VAL:
case MD_PROP_STR:
case MD_PROP_DATA: {
struct property *p = mdesc_early_alloc(sizeof(*p));
p->unique_id = unique_id++;
p->name = (char *) names + ep->name_offset;
if (ep->tag == MD_PROP_VAL) {
p->value = &ep->d.val;
p->length = 8;
} else {
p->value = data + ep->d.data.data_offset;
p->length = ep->d.data.data_len;
}
*link = p;
link = &p->next;
break;
}
u64 mdesc_next_arc(struct mdesc_handle *hp, u64 from, const char *arc_type)
{
struct mdesc_elem *ep, *base = node_block(&hp->mdesc);
const char *names = name_block(&hp->mdesc);
u64 last_node = hp->mdesc.node_sz / 16;
case MD_NOOP:
break;
if (from == MDESC_NODE_NULL || from >= last_node)
return MDESC_NODE_NULL;
default:
printk("MDESC: Warning, ignoring unknown tag type %02x\n",
ep->tag);
}
ep++;
}
ep = base + from;
ep++;
for (; ep->tag != MD_NODE_END; ep++) {
if (ep->tag != MD_PROP_ARC)
continue;
if (strcmp(names + ep->name_offset, arc_type))
continue;
return ep - base;
}
return MDESC_NODE_NULL;
}
EXPORT_SYMBOL(mdesc_next_arc);
static unsigned int __init count_nodes(struct mdesc_hdr *mdesc)
u64 mdesc_arc_target(struct mdesc_handle *hp, u64 arc)
{
struct mdesc_elem *ep = node_block(mdesc);
struct mdesc_elem *end;
unsigned int cnt = 0;
end = ((void *)ep) + mdesc->node_sz;
while (ep < end) {
if (ep->tag == MD_NODE)
cnt++;
ep++;
}
return cnt;
struct mdesc_elem *ep, *base = node_block(&hp->mdesc);
ep = base + arc;
return ep->d.val;
}
EXPORT_SYMBOL(mdesc_arc_target);
const char *mdesc_node_name(struct mdesc_handle *hp, u64 node)
{
struct mdesc_elem *ep, *base = node_block(&hp->mdesc);
const char *names = name_block(&hp->mdesc);
u64 last_node = hp->mdesc.node_sz / 16;
if (node == MDESC_NODE_NULL || node >= last_node)
return NULL;
ep = base + node;
if (ep->tag != MD_NODE)
return NULL;
return names + ep->name_offset;
}
EXPORT_SYMBOL(mdesc_node_name);
static void __init report_platform_properties(void)
{
struct mdesc_node *pn = md_find_node_by_name(NULL, "platform");
struct mdesc_handle *hp = mdesc_grab();
u64 pn = mdesc_node_by_name(hp, MDESC_NODE_NULL, "platform");
const char *s;
const u64 *v;
if (!pn) {
if (pn == MDESC_NODE_NULL) {
prom_printf("No platform node in machine-description.\n");
prom_halt();
}
s = md_get_property(pn, "banner-name", NULL);
s = mdesc_get_property(hp, pn, "banner-name", NULL);
printk("PLATFORM: banner-name [%s]\n", s);
s = md_get_property(pn, "name", NULL);
s = mdesc_get_property(hp, pn, "name", NULL);
printk("PLATFORM: name [%s]\n", s);
v = md_get_property(pn, "hostid", NULL);
v = mdesc_get_property(hp, pn, "hostid", NULL);
if (v)
printk("PLATFORM: hostid [%08lx]\n", *v);
v = md_get_property(pn, "serial#", NULL);
v = mdesc_get_property(hp, pn, "serial#", NULL);
if (v)
printk("PLATFORM: serial# [%08lx]\n", *v);
v = md_get_property(pn, "stick-frequency", NULL);
v = mdesc_get_property(hp, pn, "stick-frequency", NULL);
printk("PLATFORM: stick-frequency [%08lx]\n", *v);
v = md_get_property(pn, "mac-address", NULL);
v = mdesc_get_property(hp, pn, "mac-address", NULL);
if (v)
printk("PLATFORM: mac-address [%lx]\n", *v);
v = md_get_property(pn, "watchdog-resolution", NULL);
v = mdesc_get_property(hp, pn, "watchdog-resolution", NULL);
if (v)
printk("PLATFORM: watchdog-resolution [%lu ms]\n", *v);
v = md_get_property(pn, "watchdog-max-timeout", NULL);
v = mdesc_get_property(hp, pn, "watchdog-max-timeout", NULL);
if (v)
printk("PLATFORM: watchdog-max-timeout [%lu ms]\n", *v);
v = md_get_property(pn, "max-cpus", NULL);
v = mdesc_get_property(hp, pn, "max-cpus", NULL);
if (v)
printk("PLATFORM: max-cpus [%lu]\n", *v);
mdesc_release(hp);
}
static int inline find_in_proplist(const char *list, const char *match, int len)
......@@ -369,15 +451,17 @@ static int inline find_in_proplist(const char *list, const char *match, int len)
return 0;
}
static void __init fill_in_one_cache(cpuinfo_sparc *c, struct mdesc_node *mp)
static void __init fill_in_one_cache(cpuinfo_sparc *c,
struct mdesc_handle *hp,
u64 mp)
{
const u64 *level = md_get_property(mp, "level", NULL);
const u64 *size = md_get_property(mp, "size", NULL);
const u64 *line_size = md_get_property(mp, "line-size", NULL);
const u64 *level = mdesc_get_property(hp, mp, "level", NULL);
const u64 *size = mdesc_get_property(hp, mp, "size", NULL);
const u64 *line_size = mdesc_get_property(hp, mp, "line-size", NULL);
const char *type;
int type_len;
type = md_get_property(mp, "type", &type_len);
type = mdesc_get_property(hp, mp, "type", &type_len);
switch (*level) {
case 1:
......@@ -400,48 +484,44 @@ static void __init fill_in_one_cache(cpuinfo_sparc *c, struct mdesc_node *mp)
}
if (*level == 1) {
unsigned int i;
u64 a;
for (i = 0; i < mp->num_arcs; i++) {
struct mdesc_node *t = mp->arcs[i].arc;
mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_FWD) {
u64 target = mdesc_arc_target(hp, a);
const char *name = mdesc_node_name(hp, target);
if (strcmp(mp->arcs[i].name, "fwd"))
continue;
if (!strcmp(t->name, "cache"))
fill_in_one_cache(c, t);
if (!strcmp(name, "cache"))
fill_in_one_cache(c, hp, target);
}
}
}
static void __init mark_core_ids(struct mdesc_node *mp, int core_id)
static void __init mark_core_ids(struct mdesc_handle *hp, u64 mp, int core_id)
{
unsigned int i;
u64 a;
for (i = 0; i < mp->num_arcs; i++) {
struct mdesc_node *t = mp->arcs[i].arc;
mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_BACK) {
u64 t = mdesc_arc_target(hp, a);
const char *name;
const u64 *id;
if (strcmp(mp->arcs[i].name, "back"))
continue;
if (!strcmp(t->name, "cpu")) {
id = md_get_property(t, "id", NULL);
name = mdesc_node_name(hp, t);
if (!strcmp(name, "cpu")) {
id = mdesc_get_property(hp, t, "id", NULL);
if (*id < NR_CPUS)
cpu_data(*id).core_id = core_id;
} else {
unsigned int j;
u64 j;
for (j = 0; j < t->num_arcs; j++) {
struct mdesc_node *n = t->arcs[j].arc;
mdesc_for_each_arc(j, hp, t, MDESC_ARC_TYPE_BACK) {
u64 n = mdesc_arc_target(hp, j);
const char *n_name;
if (strcmp(t->arcs[j].name, "back"))
n_name = mdesc_node_name(hp, n);
if (strcmp(n_name, "cpu"))
continue;
if (strcmp(n->name, "cpu"))
continue;
id = md_get_property(n, "id", NULL);
id = mdesc_get_property(hp, n, "id", NULL);
if (*id < NR_CPUS)
cpu_data(*id).core_id = core_id;
}
......@@ -449,75 +529,76 @@ static void __init mark_core_ids(struct mdesc_node *mp, int core_id)
}
}
static void __init set_core_ids(void)
static void __init set_core_ids(struct mdesc_handle *hp)
{
struct mdesc_node *mp;
int idx;
u64 mp;
idx = 1;
md_for_each_node_by_name(mp, "cache") {
const u64 *level = md_get_property(mp, "level", NULL);
mdesc_for_each_node_by_name(hp, mp, "cache") {
const u64 *level;
const char *type;
int len;
level = mdesc_get_property(hp, mp, "level", NULL);
if (*level != 1)
continue;
type = md_get_property(mp, "type", &len);
type = mdesc_get_property(hp, mp, "type", &len);
if (!find_in_proplist(type, "instn", len))
continue;
mark_core_ids(mp, idx);
mark_core_ids(hp, mp, idx);
idx++;
}
}
static void __init mark_proc_ids(struct mdesc_node *mp, int proc_id)
static void __init mark_proc_ids(struct mdesc_handle *hp, u64 mp, int proc_id)
{
int i;
u64 a;
for (i = 0; i < mp->num_arcs; i++) {
struct mdesc_node *t = mp->arcs[i].arc;
mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_BACK) {
u64 t = mdesc_arc_target(hp, a);
const char *name;
const u64 *id;
if (strcmp(mp->arcs[i].name, "back"))
continue;
if (strcmp(t->name, "cpu"))
name = mdesc_node_name(hp, t);
if (strcmp(name, "cpu"))
continue;
id = md_get_property(t, "id", NULL);
id = mdesc_get_property(hp, t, "id", NULL);
if (*id < NR_CPUS)
cpu_data(*id).proc_id = proc_id;
}
}
static void __init __set_proc_ids(const char *exec_unit_name)
static void __init __set_proc_ids(struct mdesc_handle *hp,
const char *exec_unit_name)
{
struct mdesc_node *mp;
int idx;
u64 mp;
idx = 0;
md_for_each_node_by_name(mp, exec_unit_name) {
mdesc_for_each_node_by_name(hp, mp, exec_unit_name) {
const char *type;
int len;
type = md_get_property(mp, "type", &len);
type = mdesc_get_property(hp, mp, "type", &len);
if (!find_in_proplist(type, "int", len) &&
!find_in_proplist(type, "integer", len))
continue;
mark_proc_ids(mp, idx);
mark_proc_ids(hp, mp, idx);
idx++;
}
}
static void __init set_proc_ids(void)
static void __init set_proc_ids(struct mdesc_handle *hp)
{
__set_proc_ids("exec_unit");
__set_proc_ids("exec-unit");
__set_proc_ids(hp, "exec_unit");
__set_proc_ids(hp, "exec-unit");
}
static void __init get_one_mondo_bits(const u64 *p, unsigned int *mask, unsigned char def)
......@@ -538,35 +619,37 @@ static void __init get_one_mondo_bits(const u64 *p, unsigned int *mask, unsigned
*mask = ((1U << def) * 64U) - 1U;
}
static void __init get_mondo_data(struct mdesc_node *mp, struct trap_per_cpu *tb)
static void __init get_mondo_data(struct mdesc_handle *hp, u64 mp,
struct trap_per_cpu *tb)
{
const u64 *val;
val = md_get_property(mp, "q-cpu-mondo-#bits", NULL);
val = mdesc_get_property(hp, mp, "q-cpu-mondo-#bits", NULL);
get_one_mondo_bits(val, &tb->cpu_mondo_qmask, 7);
val = md_get_property(mp, "q-dev-mondo-#bits", NULL);
val = mdesc_get_property(hp, mp, "q-dev-mondo-#bits", NULL);
get_one_mondo_bits(val, &tb->dev_mondo_qmask, 7);
val = md_get_property(mp, "q-resumable-#bits", NULL);
val = mdesc_get_property(hp, mp, "q-resumable-#bits", NULL);
get_one_mondo_bits(val, &tb->resum_qmask, 6);
val = md_get_property(mp, "q-nonresumable-#bits", NULL);
val = mdesc_get_property(hp, mp, "q-nonresumable-#bits", NULL);
get_one_mondo_bits(val, &tb->nonresum_qmask, 2);
}
static void __init mdesc_fill_in_cpu_data(void)
{
struct mdesc_node *mp;
struct mdesc_handle *hp = mdesc_grab();
u64 mp;
ncpus_probed = 0;
md_for_each_node_by_name(mp, "cpu") {
const u64 *id = md_get_property(mp, "id", NULL);
const u64 *cfreq = md_get_property(mp, "clock-frequency", NULL);
mdesc_for_each_node_by_name(hp, mp, "cpu") {
const u64 *id = mdesc_get_property(hp, mp, "id", NULL);
const u64 *cfreq = mdesc_get_property(hp, mp, "clock-frequency", NULL);
struct trap_per_cpu *tb;
cpuinfo_sparc *c;
unsigned int i;
int cpuid;
u64 a;
ncpus_probed++;
......@@ -589,29 +672,25 @@ static void __init mdesc_fill_in_cpu_data(void)
c->clock_tick = *cfreq;
tb = &trap_block[cpuid];
get_mondo_data(mp, tb);
for (i = 0; i < mp->num_arcs; i++) {
struct mdesc_node *t = mp->arcs[i].arc;
unsigned int j;
get_mondo_data(hp, mp, tb);
if (strcmp(mp->arcs[i].name, "fwd"))
continue;
mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_FWD) {
u64 j, t = mdesc_arc_target(hp, a);
const char *t_name;
if (!strcmp(t->name, "cache")) {
fill_in_one_cache(c, t);
t_name = mdesc_node_name(hp, t);
if (!strcmp(t_name, "cache")) {
fill_in_one_cache(c, hp, t);
continue;
}
for (j = 0; j < t->num_arcs; j++) {
struct mdesc_node *n;
mdesc_for_each_arc(j, hp, t, MDESC_ARC_TYPE_FWD) {
u64 n = mdesc_arc_target(hp, j);
const char *n_name;
n = t->arcs[j].arc;
if (strcmp(t->arcs[j].name, "fwd"))
continue;
if (!strcmp(n->name, "cache"))
fill_in_one_cache(c, n);
n_name = mdesc_node_name(hp, n);
if (!strcmp(n_name, "cache"))
fill_in_one_cache(c, hp, n);
}
}
......@@ -628,44 +707,39 @@ static void __init mdesc_fill_in_cpu_data(void)
sparc64_multi_core = 1;
#endif
set_core_ids();
set_proc_ids();
set_core_ids(hp);
set_proc_ids(hp);
smp_fill_in_sib_core_maps();
mdesc_release(hp);
}
void __init sun4v_mdesc_init(void)
{
struct mdesc_handle *hp;
unsigned long len, real_len, status;
(void) sun4v_mach_desc(0UL, 0UL, &len);
printk("MDESC: Size is %lu bytes.\n", len);
main_mdesc = mdesc_early_alloc(len);
hp = mdesc_alloc(len, &bootmem_mdesc_memops);
if (hp == NULL) {
prom_printf("MDESC: alloc of %lu bytes failed.\n", len);
prom_halt();
}
status = sun4v_mach_desc(__pa(main_mdesc), len, &real_len);
status = sun4v_mach_desc(__pa(&hp->mdesc), len, &real_len);
if (status != HV_EOK || real_len > len) {
prom_printf("sun4v_mach_desc fails, err(%lu), "
"len(%lu), real_len(%lu)\n",
status, len, real_len);
mdesc_free(hp);
prom_halt();
}
len = count_nodes(main_mdesc);
printk("MDESC: %lu nodes.\n", len);
len = roundup_pow_of_two(len);
mdesc_hash = mdesc_early_alloc(len * sizeof(struct mdesc_node *));
mdesc_hash_size = len;
printk("MDESC: Hash size %lu entries.\n", len);
build_all_nodes(main_mdesc);
printk("MDESC: Built graph with %u bytes of memory.\n",
mdesc_early_allocated);
cur_mdesc = hp;
report_platform_properties();
mdesc_fill_in_cpu_data();
......
......@@ -147,30 +147,6 @@ void vio_unregister_driver(struct vio_driver *viodrv)
}
EXPORT_SYMBOL(vio_unregister_driver);
struct mdesc_node *vio_find_endpoint(struct vio_dev *vdev)
{
struct mdesc_node *endp, *mp = vdev->mp;
int i;
endp = NULL;
for (i = 0; i < mp->num_arcs; i++) {
struct mdesc_node *t;
if (strcmp(mp->arcs[i].name, "fwd"))
continue;
t = mp->arcs[i].arc;
if (strcmp(t->name, "channel-endpoint"))
continue;
endp = t;
break;
}
return endp;
}
EXPORT_SYMBOL(vio_find_endpoint);
static void __devinit vio_dev_release(struct device *dev)
{
kfree(to_vio_dev(dev));
......@@ -197,22 +173,47 @@ struct device_node *cdev_node;
static struct vio_dev *root_vdev;
static u64 cdev_cfg_handle;
static struct vio_dev *vio_create_one(struct mdesc_node *mp,
static void vio_fill_channel_info(struct mdesc_handle *hp, u64 mp,
struct vio_dev *vdev)
{
u64 a;
mdesc_for_each_arc(a, hp, mp, MDESC_ARC_TYPE_FWD) {
const u64 *chan_id;
const u64 *irq;
u64 target;
target = mdesc_arc_target(hp, a);
irq = mdesc_get_property(hp, target, "tx-ino", NULL);
if (irq)
vdev->tx_irq = sun4v_build_virq(cdev_cfg_handle, *irq);
irq = mdesc_get_property(hp, target, "rx-ino", NULL);
if (irq)
vdev->rx_irq = sun4v_build_virq(cdev_cfg_handle, *irq);
chan_id = mdesc_get_property(hp, target, "id", NULL);
if (chan_id)
vdev->channel_id = *chan_id;
}
}
static struct vio_dev *vio_create_one(struct mdesc_handle *hp, u64 mp,
struct device *parent)
{
const char *type, *compat;
struct device_node *dp;
struct vio_dev *vdev;
const u64 *irq;
int err, clen;
type = md_get_property(mp, "device-type", NULL);
type = mdesc_get_property(hp, mp, "device-type", NULL);
if (!type) {
type = md_get_property(mp, "name", NULL);
type = mdesc_get_property(hp, mp, "name", NULL);
if (!type)
type = mp->name;
type = mdesc_node_name(hp, mp);
}
compat = md_get_property(mp, "device-type", &clen);
compat = mdesc_get_property(hp, mp, "device-type", &clen);
vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
if (!vdev) {
......@@ -225,15 +226,13 @@ static struct vio_dev *vio_create_one(struct mdesc_node *mp,
vdev->compat = compat;
vdev->compat_len = clen;
irq = md_get_property(mp, "tx-ino", NULL);
if (irq)
mp->irqs[0] = sun4v_build_virq(cdev_cfg_handle, *irq);
vdev->channel_id = ~0UL;
vdev->tx_irq = ~0;
vdev->rx_irq = ~0;
irq = md_get_property(mp, "rx-ino", NULL);
if (irq)
mp->irqs[1] = sun4v_build_virq(cdev_cfg_handle, *irq);
vio_fill_channel_info(hp, mp, vdev);
snprintf(vdev->dev.bus_id, BUS_ID_SIZE, "%lx", mp->node);
snprintf(vdev->dev.bus_id, BUS_ID_SIZE, "%lx", mp);
vdev->dev.parent = parent;
vdev->dev.bus = &vio_bus_type;
vdev->dev.release = vio_dev_release;
......@@ -267,46 +266,43 @@ static struct vio_dev *vio_create_one(struct mdesc_node *mp,
return vdev;
}
static void walk_tree(struct mdesc_node *n, struct vio_dev *parent)
static void walk_tree(struct mdesc_handle *hp, u64 n, struct vio_dev *parent)
{
int i;
u64 a;
for (i = 0; i < n->num_arcs; i++) {
struct mdesc_node *mp;
mdesc_for_each_arc(a, hp, n, MDESC_ARC_TYPE_FWD) {
struct vio_dev *vdev;
u64 target;
if (strcmp(n->arcs[i].name, "fwd"))
continue;
mp = n->arcs[i].arc;
vdev = vio_create_one(mp, &parent->dev);
if (vdev && mp->num_arcs)
walk_tree(mp, vdev);
target = mdesc_arc_target(hp, a);
vdev = vio_create_one(hp, target, &parent->dev);
if (vdev)
walk_tree(hp, target, vdev);
}
}
static void create_devices(struct mdesc_node *root)
static void create_devices(struct mdesc_handle *hp, u64 root)
{
struct mdesc_node *mp;
u64 mp;
root_vdev = vio_create_one(root, NULL);
root_vdev = vio_create_one(hp, root, NULL);
if (!root_vdev) {
printk(KERN_ERR "VIO: Coult not create root device.\n");
return;
}
walk_tree(root, root_vdev);
walk_tree(hp, root, root_vdev);
/* Domain services is odd as it doesn't sit underneath the
* channel-devices node, so we plug it in manually.
*/
mp = md_find_node_by_name(NULL, "domain-services");
if (mp) {
struct vio_dev *parent = vio_create_one(mp, &root_vdev->dev);
mp = mdesc_node_by_name(hp, MDESC_NODE_NULL, "domain-services");
if (mp != MDESC_NODE_NULL) {
struct vio_dev *parent = vio_create_one(hp, mp,
&root_vdev->dev);
if (parent)
walk_tree(mp, parent);
walk_tree(hp, mp, parent);
}
}
......@@ -316,40 +312,47 @@ const char *cfg_handle_prop = "cfg-handle";
static int __init vio_init(void)
{
struct mdesc_node *root;
struct mdesc_handle *hp;
const char *compat;
const u64 *cfg_handle;
int err, len;
u64 root;
hp = mdesc_grab();
if (!hp)
return 0;
root = md_find_node_by_name(NULL, channel_devices_node);
if (!root) {
root = mdesc_node_by_name(hp, MDESC_NODE_NULL, channel_devices_node);
if (root == MDESC_NODE_NULL) {
printk(KERN_INFO "VIO: No channel-devices MDESC node.\n");
mdesc_release(hp);
return 0;
}
cdev_node = of_find_node_by_name(NULL, "channel-devices");
err = -ENODEV;
if (!cdev_node) {
printk(KERN_INFO "VIO: No channel-devices OBP node.\n");
return -ENODEV;
goto out_release;
}
compat = md_get_property(root, "compatible", &len);
compat = mdesc_get_property(hp, root, "compatible", &len);
if (!compat) {
printk(KERN_ERR "VIO: Channel devices lacks compatible "
"property\n");
return -ENODEV;
goto out_release;
}
if (!find_in_proplist(compat, channel_devices_compat, len)) {
printk(KERN_ERR "VIO: Channel devices node lacks (%s) "
"compat entry.\n", channel_devices_compat);
return -ENODEV;
goto out_release;
}
cfg_handle = md_get_property(root, cfg_handle_prop, NULL);
cfg_handle = mdesc_get_property(hp, root, cfg_handle_prop, NULL);
if (!cfg_handle) {
printk(KERN_ERR "VIO: Channel devices lacks %s property\n",
cfg_handle_prop);
return -ENODEV;
goto out_release;
}
cdev_cfg_handle = *cfg_handle;
......@@ -361,9 +364,15 @@ static int __init vio_init(void)
return err;
}
create_devices(root);
create_devices(hp, root);
mdesc_release(hp);
return 0;
out_release:
mdesc_release(hp);
return err;
}
postcore_initcall(vio_init);
......@@ -136,7 +136,7 @@ static int process_unknown(struct vio_driver_state *vio, void *arg)
pkt->type, pkt->stype, pkt->stype_env, pkt->sid);
printk(KERN_ERR "vio: ID[%lu] Resetting connection.\n",
vio->channel_id);
vio->vdev->channel_id);
ldc_disconnect(vio->lp);
......@@ -678,21 +678,11 @@ extern int vio_ldc_alloc(struct vio_driver_state *vio,
{
struct ldc_channel_config cfg = *base_cfg;
struct ldc_channel *lp;
const u64 *id;
id = md_get_property(vio->endpoint, "id", NULL);
if (!id) {
printk(KERN_ERR "%s: Channel lacks id property.\n",
vio->name);
return -ENODEV;
}
vio->channel_id = *id;
cfg.rx_irq = vio->rx_irq;
cfg.tx_irq = vio->tx_irq;
cfg.tx_irq = vio->vdev->tx_irq;
cfg.rx_irq = vio->vdev->rx_irq;
lp = ldc_alloc(vio->channel_id, &cfg, event_arg);
lp = ldc_alloc(vio->vdev->channel_id, &cfg, event_arg);
if (IS_ERR(lp))
return PTR_ERR(lp);
......@@ -728,7 +718,7 @@ void vio_port_up(struct vio_driver_state *vio)
if (err)
printk(KERN_WARNING "%s: Port %lu bind failed, "
"err=%d\n",
vio->name, vio->channel_id, err);
vio->name, vio->vdev->channel_id, err);
}
if (!err) {
......@@ -736,7 +726,7 @@ void vio_port_up(struct vio_driver_state *vio)
if (err)
printk(KERN_WARNING "%s: Port %lu connect failed, "
"err=%d\n",
vio->name, vio->channel_id, err);
vio->name, vio->vdev->channel_id, err);
}
if (err) {
unsigned long expires = jiffies + HZ;
......@@ -757,9 +747,9 @@ static void vio_port_timer(unsigned long _arg)
}
int vio_driver_init(struct vio_driver_state *vio, struct vio_dev *vdev,
u8 dev_class, struct mdesc_node *channel_endpoint,
struct vio_version *ver_table, int ver_table_size,
struct vio_driver_ops *ops, char *name)
u8 dev_class, struct vio_version *ver_table,
int ver_table_size, struct vio_driver_ops *ops,
char *name)
{
switch (dev_class) {
case VDEV_NETWORK:
......@@ -777,9 +767,6 @@ int vio_driver_init(struct vio_driver_state *vio, struct vio_dev *vdev,
!ops->handshake_complete)
return -EINVAL;
if (!channel_endpoint)
return -EINVAL;
if (!ver_table || ver_table_size < 0)
return -EINVAL;
......@@ -793,10 +780,6 @@ int vio_driver_init(struct vio_driver_state *vio, struct vio_dev *vdev,
vio->dev_class = dev_class;
vio->vdev = vdev;
vio->endpoint = channel_endpoint;
vio->tx_irq = channel_endpoint->irqs[0];
vio->rx_irq = channel_endpoint->irqs[1];
vio->ver_table = ver_table;
vio->ver_table_entries = ver_table_size;
......
......@@ -750,7 +750,7 @@ static struct vio_driver_ops vdc_vio_ops = {
static int __devinit vdc_port_probe(struct vio_dev *vdev,
const struct vio_device_id *id)
{
struct mdesc_node *endp;
struct mdesc_handle *hp;
struct vdc_port *port;
unsigned long flags;
struct vdc *vp;
......@@ -763,26 +763,24 @@ static int __devinit vdc_port_probe(struct vio_dev *vdev,
return -ENODEV;
}
endp = vio_find_endpoint(vdev);
if (!endp) {
printk(KERN_ERR PFX "Port lacks channel-endpoint.\n");
return -ENODEV;
}
hp = mdesc_grab();
port_id = md_get_property(vdev->mp, "id", NULL);
port_id = mdesc_get_property(hp, vdev->mp, "id", NULL);
err = -ENODEV;
if (!port_id) {
printk(KERN_ERR PFX "Port lacks id property.\n");
return -ENODEV;
goto err_out_release_mdesc;
}
if ((*port_id << PARTITION_SHIFT) & ~(u64)MINORMASK) {
printk(KERN_ERR PFX "Port id [%lu] too large.\n", *port_id);
return -ENODEV;
goto err_out_release_mdesc;
}
port = kzalloc(sizeof(*port), GFP_KERNEL);
err = -ENOMEM;
if (!port) {
printk(KERN_ERR PFX "Cannot allocate vdc_port.\n");
return -ENOMEM;
goto err_out_release_mdesc;
}
port->vp = vp;
......@@ -797,7 +795,7 @@ static int __devinit vdc_port_probe(struct vio_dev *vdev,
snprintf(port->disk_name, sizeof(port->disk_name),
VDCBLK_NAME "%c", 'a' + (port->dev_no % 26));
err = vio_driver_init(&port->vio, vdev, VDEV_DISK, endp,
err = vio_driver_init(&port->vio, vdev, VDEV_DISK,
vdc_versions, ARRAY_SIZE(vdc_versions),
&vdc_vio_ops, port->disk_name);
if (err)
......@@ -828,6 +826,8 @@ static int __devinit vdc_port_probe(struct vio_dev *vdev,
dev_set_drvdata(&vdev->dev, port);
mdesc_release(hp);
return 0;
err_out_free_tx_ring:
......@@ -839,6 +839,8 @@ static int __devinit vdc_port_probe(struct vio_dev *vdev,
err_out_free_port:
kfree(port);
err_out_release_mdesc:
mdesc_release(hp);
return err;
}
......
......@@ -892,7 +892,7 @@ const char *remote_macaddr_prop = "remote-mac-address";
static int __devinit vnet_port_probe(struct vio_dev *vdev,
const struct vio_device_id *id)
{
struct mdesc_node *endp;
struct mdesc_handle *hp;
struct vnet_port *port;
unsigned long flags;
struct vnet *vp;
......@@ -905,23 +905,21 @@ static int __devinit vnet_port_probe(struct vio_dev *vdev,
return -ENODEV;
}
rmac = md_get_property(vdev->mp, remote_macaddr_prop, &len);
hp = mdesc_grab();
rmac = mdesc_get_property(hp, vdev->mp, remote_macaddr_prop, &len);
err = -ENODEV;
if (!rmac) {
printk(KERN_ERR PFX "Port lacks %s property.\n",
remote_macaddr_prop);
return -ENODEV;
}
endp = vio_find_endpoint(vdev);
if (!endp) {
printk(KERN_ERR PFX "Port lacks channel-endpoint.\n");
return -ENODEV;
goto err_out_put_mdesc;
}
port = kzalloc(sizeof(*port), GFP_KERNEL);
err = -ENOMEM;
if (!port) {
printk(KERN_ERR PFX "Cannot allocate vnet_port.\n");
return -ENOMEM;
goto err_out_put_mdesc;
}
for (i = 0; i < ETH_ALEN; i++)
......@@ -929,7 +927,7 @@ static int __devinit vnet_port_probe(struct vio_dev *vdev,
port->vp = vp;
err = vio_driver_init(&port->vio, vdev, VDEV_NETWORK, endp,
err = vio_driver_init(&port->vio, vdev, VDEV_NETWORK,
vnet_versions, ARRAY_SIZE(vnet_versions),
&vnet_vio_ops, vp->dev->name);
if (err)
......@@ -947,7 +945,7 @@ static int __devinit vnet_port_probe(struct vio_dev *vdev,
INIT_LIST_HEAD(&port->list);
switch_port = 0;
if (md_get_property(vdev->mp, "switch-port", NULL) != NULL)
if (mdesc_get_property(hp, vdev->mp, "switch-port", NULL) != NULL)
switch_port = 1;
spin_lock_irqsave(&vp->lock, flags);
......@@ -969,6 +967,8 @@ static int __devinit vnet_port_probe(struct vio_dev *vdev,
vio_port_up(&port->vio);
mdesc_release(hp);
return 0;
err_out_free_ldc:
......@@ -977,6 +977,8 @@ static int __devinit vnet_port_probe(struct vio_dev *vdev,
err_out_free_port:
kfree(port);
err_out_put_mdesc:
mdesc_release(hp);
return err;
}
......@@ -1029,6 +1031,7 @@ static int __devinit vnet_probe(struct vio_dev *vdev,
const struct vio_device_id *id)
{
static int vnet_version_printed;
struct mdesc_handle *hp;
struct net_device *dev;
struct vnet *vp;
const u64 *mac;
......@@ -1037,7 +1040,9 @@ static int __devinit vnet_probe(struct vio_dev *vdev,
if (vnet_version_printed++ == 0)
printk(KERN_INFO "%s", version);
mac = md_get_property(vdev->mp, local_mac_prop, &len);
hp = mdesc_grab();
mac = mdesc_get_property(hp, vdev->mp, local_mac_prop, &len);
if (!mac) {
printk(KERN_ERR PFX "vnet lacks %s property.\n",
local_mac_prop);
......@@ -1093,12 +1098,15 @@ static int __devinit vnet_probe(struct vio_dev *vdev,
dev_set_drvdata(&vdev->dev, vp);
mdesc_release(hp);
return 0;
err_out_free_dev:
free_netdev(dev);
err_out:
mdesc_release(hp);
return err;
}
......
......@@ -4,36 +4,43 @@
#include <linux/types.h>
#include <asm/prom.h>
struct mdesc_node;
struct mdesc_arc {
const char *name;
struct mdesc_node *arc;
};
struct mdesc_node {
const char *name;
u64 node;
unsigned int unique_id;
unsigned int num_arcs;
unsigned int irqs[2];
struct property *properties;
struct mdesc_node *hash_next;
struct mdesc_node *allnodes_next;
struct mdesc_arc arcs[0];
};
extern struct mdesc_node *md_find_node_by_name(struct mdesc_node *from,
const char *name);
#define md_for_each_node_by_name(__mn, __name) \
for (__mn = md_find_node_by_name(NULL, __name); __mn; \
__mn = md_find_node_by_name(__mn, __name))
extern struct property *md_find_property(const struct mdesc_node *mp,
const char *name,
int *lenp);
extern const void *md_get_property(const struct mdesc_node *mp,
const char *name,
int *lenp);
struct mdesc_handle;
/* Machine description operations are to be surrounded by grab and
* release calls. The mdesc_handle returned from the grab is
* the first argument to all of the operational calls that work
* on mdescs.
*/
extern struct mdesc_handle *mdesc_grab(void);
extern void mdesc_release(struct mdesc_handle *);
#define MDESC_NODE_NULL (~(u64)0)
extern u64 mdesc_node_by_name(struct mdesc_handle *handle,
u64 from_node, const char *name);
#define mdesc_for_each_node_by_name(__hdl, __node, __name) \
for (__node = mdesc_node_by_name(__hdl, MDESC_NODE_NULL, __name); \
(__node) != MDESC_NODE_NULL; \
__node = mdesc_node_by_name(__hdl, __node, __name))
extern const void *mdesc_get_property(struct mdesc_handle *handle,
u64 node, const char *name, int *lenp);
#define MDESC_ARC_TYPE_FWD "fwd"
#define MDESC_ARC_TYPE_BACK "back"
extern u64 mdesc_next_arc(struct mdesc_handle *handle, u64 from,
const char *arc_type);
#define mdesc_for_each_arc(__arc, __hdl, __node, __type) \
for (__arc = mdesc_next_arc(__hdl, __node, __type); \
(__arc) != MDESC_NODE_NULL; \
__arc = mdesc_next_arc(__hdl, __arc, __type))
extern u64 mdesc_arc_target(struct mdesc_handle *hp, u64 arc);
extern const char *mdesc_node_name(struct mdesc_handle *hp, u64 node);
extern void mdesc_update(void);
extern void sun4v_mdesc_init(void);
......
......@@ -265,13 +265,18 @@ static inline u32 vio_dring_avail(struct vio_dring_state *dr,
}
struct vio_dev {
struct mdesc_node *mp;
u64 mp;
struct device_node *dp;
const char *type;
const char *compat;
int compat_len;
unsigned long channel_id;
unsigned int tx_irq;
unsigned int rx_irq;
struct device dev;
};
......@@ -345,16 +350,10 @@ struct vio_driver_state {
struct vio_dev *vdev;
unsigned long channel_id;
unsigned int tx_irq;
unsigned int rx_irq;
struct timer_list timer;
struct vio_version ver;
struct mdesc_node *endpoint;
struct vio_version *ver_table;
int ver_table_entries;
......@@ -365,7 +364,8 @@ struct vio_driver_state {
#define viodbg(TYPE, f, a...) \
do { if (vio->debug & VIO_DEBUG_##TYPE) \
printk(KERN_INFO "vio: ID[%lu] " f, vio->channel_id, ## a); \
printk(KERN_INFO "vio: ID[%lu] " f, \
vio->vdev->channel_id, ## a); \
} while (0)
extern int vio_register_driver(struct vio_driver *drv);
......@@ -392,11 +392,10 @@ extern int vio_ldc_alloc(struct vio_driver_state *vio,
struct ldc_channel_config *base_cfg, void *event_arg);
extern void vio_ldc_free(struct vio_driver_state *vio);
extern int vio_driver_init(struct vio_driver_state *vio, struct vio_dev *vdev,
u8 dev_class, struct mdesc_node *channel_endpoint,
struct vio_version *ver_table, int ver_table_size,
struct vio_driver_ops *ops, char *name);
u8 dev_class, struct vio_version *ver_table,
int ver_table_size, struct vio_driver_ops *ops,
char *name);
extern struct mdesc_node *vio_find_endpoint(struct vio_dev *vdev);
extern void vio_port_up(struct vio_driver_state *vio);
#endif /* _SPARC64_VIO_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment