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