[BACK]Return to config_alloc.c CVS log [TXT][DIR] Up to [local] / prex-old / dev / core

File: [local] / prex-old / dev / core / config_alloc.c (download)

Revision 1.1, Fri Aug 8 12:37:11 2008 UTC (15 years, 8 months ago) by nbrk
Branch: MAIN
CVS Tags: HEAD

Heads up! Implement universal device attachment and autoconfiguration machinery.
This is somewhat similar to traditional BSD autoconf but much more simple.
Three basic data structures involved in autoconfiguration process are:
struct device, which represents abstract device and its private (driver softc) data;
struct driver, which holds {attach,match,detach} entries, name and softc size;
struct attachment, which tells us how drivers are interacted with each other.
Attachment basically describes how to attach devices in system.
Machine specified part should export arrays config_table[] and *drivers[] for config.

This might have broken i386 & gba tree, but there is only a question of time.

/*
 * $Id: config_alloc.c,v 1.1 2008/08/08 12:37:11 nbrk Exp $
 */
/*
 * Allocate and initialize new device structure.
 */
#include <driver.h>

struct device
*config_alloc_device(struct driver *drv)
{
	struct device	*devp;

	/* device itself */
	devp = kmem_alloc(sizeof(struct device));
	if (devp == NULL)
		panic("config: can't allocate memory for device");

	/* device data */
	if (drv->dr_datasize != 0) {
		/* XXX page_alloc() ? */
		devp->dv_data = kmem_alloc(drv->dr_datasize);
		if (devp->dv_data == NULL)
			panic("config: can't allocate memory dor device data");
	}

	devp->dv_xname = drv->dr_name;

	/* will be changed by config later */
	devp->dv_unit = 0;
	devp->dv_flags = 0;	/* XXX */
	devp->dv_parent = NULL;

	return(devp);
}


void
config_free_device(struct device *devp)
{
	kmem_free(devp->dv_data);
	kmem_free(devp);
}