注册oracle驱动,注册设备 ID - 编写适用于 Oracle® Solaris 11.2 的设备驱动程序

注册设备 ID

通常,驱动程序在其 attach(9E) 处理程序中初始化和注册设备 ID。如上所述,驱动程序负责注册永久设备 ID。同时,驱动程序可能需要处理可直接提供唯一 ID (WWN) 的设备和向稳定存储器写入及从稳定存储器读取虚构 ID 的设备。

注册设备提供的 ID

如果设备可以为驱动程序提供唯一的标识符,则驱动程序可以直接使用此标识符初始化设备 ID 并使用 Oracle Solaris DDI 注册此 ID。/*

* The device provides a guaranteed unique identifier,

* in this case a SCSI3-WWN. The WWN for the device has been

* stored in the device's soft state.

*/

if (ddi_devid_init(dip, DEVID_SCSI3_WWN, un->un_wwn_len, un->un_wwn,

&un->un_devid) != DDI_SUCCESS)

return (DDI_FAILURE);

(void) ddi_devid_register(dip, un->un_devid);

注册虚构 ID

驱动程序还可能为不直接提供唯一 ID 的设备注册设备 ID。注册这些 ID 需要设备能够存储并检索保留区中的少量数据。随后,驱动程序可创建虚构设备 ID 并将其写入保留区中。/*

* the device doesn't supply a unique ID, attempt to read

* a fabricated ID from the device's reserved data.

*/

if (xxx_read_deviceid(un, &devid_buf) == XXX_OK) {

if (ddi_devid_valid(devid_buf) == DDI_SUCCESS) {

devid_sz = ddi_devi_sizeof(devid_buf);

un->un_devid = kmem_alloc(devid_sz, KM_SLEEP);

bcopy(devid_buf, un->un_devid, devid_sz);

ddi_devid_register(dip, un->un_devid);

return (XXX_OK);

}

}

/*

* we failed to read a valid device ID from the device

* fabricate an ID, store it on the device, and register

* it with the DDI

*/

if (ddi_devid_init(dip, DEVID_FAB, 0, NULL, &un->un_devid)

== DDI_FAILURE) {

return (XXX_FAILURE);

}

if (xxx_write_deviceid(un) != XXX_OK) {

ddi_devid_free(un->un_devid);

un->un_devid = NULL;

return (XXX_FAILURE);

}

ddi_devid_register(dip, un->un_devid);

return (XXX_OK);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值