forked from xuzhongxing/fuchsia-notes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ahci.txt
84 lines (72 loc) · 3.01 KB
/
ahci.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
\section{ahci driver}
\begin{verbatim}
在此之前:
kpci会让dc创建一个pci设备,这个pci设备是isolated,
所以会在dc端创建一个proxy设备,这个proxy设备
会启动一个新的devhost进程,使用pci.proxy.so
然后dh_bind_driver会加载正式的ahci驱动,这个驱动运行于上面的新dh进程里。创建一个新的
设备在dc端。
kpci.c: (dev host)
pci_drv_bind()
pci_init_child(parent, index)
zx_pci_get_nth_device()
device = calloc(1, sizeof(kpci_device_t));
device_add_args_t args = {
.version = DEVICE_ADD_ARGS_VERSION,
.name = name,
.ctx = device,
.ops = &pci_device_proto,
.proto_id = ZX_PROTOCOL_PCI,
.props = device_props,
.prop_count = countof(device_props),
.proxy_args = argstr,
.flags = DEVICE_ADD_MUST_ISOLATE,
};
device_add(parent, &args, &device->zxdev);
device_add_from_driver(__zircon_driver_rec__.driver, parent, args, out)
devhost_device_create(drv, parent, args->name, args->ctx, args->ops, &dev);
zx_device_t* dev = malloc(sizeof(zx_device_t));
devhost_device_add(dev, parent, args->props, args->prop_count, args->proxy_args);
devhost_add(parent, dev, proxy_args, props, prop_count);
iostate_t* ios = calloc(1, sizeof(*ios));
msg.op = (child->flags & DEV_FLAG_INVISIBLE) ? DC_OP_ADD_DEVICE_INVISIBLE : DC_OP_ADD_DEVICE;
zx_channel_create(0, &hrpc, &hsend)
dc_msg_rpc(parent->rpc, &msg, msglen, &hsend, 1, &rsp, sizeof(rsp), NULL, NULL)
dev coordinator:
dc_add_device(dev, hin[0], &msg, name, args, data,
msg.op == DC_OP_ADD_DEVICE_INVISIBLE))
dev->hrpc = hrpc;
dev->prop_count = msg->datalen / sizeof(zx_device_prop_t);
dev->protocol_id = msg->protocol_id;
dev->host = parent->host;
dev->parent = parent;
devfs_publish(parent, dev)
devfs_mknode(dev, dev->name, 0);
dev->ph.handle = hrpc;
dev->ph.waitfor = ZX_CHANNEL_READABLE | ZX_CHANNEL_PEER_CLOSED;
dev->ph.func = dc_handle_device;
port_wait(&dc_port, &dev->ph)
queue_work(&dev->work, WORK_DEVICE_ADDED, 0)
case WORK_DEVICE_ADDED:
dc_handle_new_device(dev);
dc_is_bindable(drv, dev->protocol_id,
dev->props, dev->prop_count, true))
dc_attempt_bind(drv, dev);
dc_prepare_proxy(dev)
dc_create_proxy(dev)
libname = "bus-pci.proxy.so"
dc_new_devhost(devhostname, dev->host,&dev->proxy->host)
有自己的devhost进程
dh_create_device(dev->proxy, dev->proxy->host, arg1, h1))
zx_channel_create(0, handle, &hrpc)
msg.op = DC_OP_CREATE_DEVICE
call proxy.c's create() api
dh_bind_driver(dev->proxy, drv->libname);
msg.op = DC_OP_BIND_DRIVER;
zx_channel_write(dev->hrpc, 0, &msg, mlen, &vmo, 1)
dev host:
case DC_OP_CREATE_DEVICE:
case DC_OP_BIND_DRIVER:
ahci_bind()
dev是父设备,是proxy设备,是独立的devhost进程
\end{verbatim}