Date: Sun, 14 Feb 1999 16:58:35 -0500 (EST) From: Bill Paul <wpaul@skynet.ctr.columbia.edu> To: hackers@FreeBSD.ORG Cc: current@FreeBSD.ORG Subject: How the hell does one create a new bus?! Message-ID: <199902142158.QAA00307@skynet.ctr.columbia.edu>
next in thread | raw e-mail | index | archive | help
Grrrr. Alright, I give up: how does one create a new 'bus' layer? By that I mean like /sys/dev/iicbus and /sys/dev/smbus. Yes, I've read the code in these two directories, but I'm confused as to which parts relate to the bus architecture in general and which parts are speficic to the I2C and system management implementation. >From what I can tell, you need the following: - foobus_if.m, a file which describes the functions that drivers for devices attached to this kind bus can perform. - foobus.c and foobus.h WHAT EXACTLY GOES IN HERE!? - fooconf.c and fooconf.h WHAT EXACTLY GOES IN HERE!? - Some type of top level driver for the device which implements the bus. - Various drivers for devices attached to the bus. In my particular case, I'm trying to create a bus layer for MII-compliant PHYs attached to ethernet controller chips. The ethernet controller is the bus controller device: each MII management bus can have up to 32 PHY devices attached to it (though in general you rarely have more than two). Each ethernet driver exports three functions to the MII code: mii_read(), mii_write() and mii_statchg(). The first two allow reading and writing of the registers of a PHY at a particular address (i.e. mii_read(dev, phyadd, regaddr), mii_write(dev, phyaddr, regaddr, val)). The mii_statchg() routine is a callback routine: when one of the lower-level PHY drivers does a media change, it calls back to the ethernet driver to let it know. (This is necessary because some media changes also require updating registers on the ethernet controller itself. For instance, on the ThunderLAN chip, if the PHY is set for full duplex, the ThunderLAN chip itself also has to be programmed for full duplex at the same time). The PHY drivers themselves (as they are now) export three functions to the MII glue code: foophy_probe(), foophy_attach() and foophy_service(). The middle MII layer exports mii_phy_probe(), mii_pollstat(), mii_statchg() and mii_tick() back to the ethernet driver. I've faked things up for now using linker sets, but I'd prefer to make everything fit into the bus framework if possible. Unfortunately, there doesn't appear to be a nice generic example that shows how to create a new bus layer, and the existing code confuses the hell out of me. For example, both the iicbus and smbus code use interrupt routines, but the MII code doesn't need interrupts (PHY devices don't normally generate interrupts). Also, how do I know exactly what goes into the foobus.c and fooconf.c modules? The smbconf.c and iiconf.c modules appear to have 'request_bus' routines that do things with tsleep(); what is this for? Does every bus need this or is it specific to the I2C and SMB stuff? The ppbus code is no help as it doesn't actually use this framework, and the usb bus stuff is a mutant pile of macros and #ifdefs. What this stuff needs is a developer's guide; a clearcut explanation of how to create new busses, how to create top level bus drivers and how to create drivers for devices attached to busses. If anyone can point me at such a guide or can just explain to me how this nonsense is supposed to work, I'd be grateful. -Bill -- ============================================================================= -Bill Paul (212) 854-6020 | System Manager, Master of Unix-Fu Work: wpaul@ctr.columbia.edu | Center for Telecommunications Research Home: wpaul@skynet.ctr.columbia.edu | Columbia University, New York City ============================================================================= "It is not I who am crazy; it is I who am mad!" - Ren Hoek, "Space Madness" ============================================================================= To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199902142158.QAA00307>