1devmap_unmap(9E) Driver Entry Points devmap_unmap(9E)
2
3
4
6 devmap_unmap - device mapping unmap entry point
7
9 #include <sys/ddi.h>
10 #include <sys/sunddi.h>
11
12
13
14 void prefixdevmap_unmap(devmap_cookie_t dhp, void *pvtp,
15 offset_t off, size_tlen, devmap_cookie_t new_dhp1,
16 void **new_pvtp1, devmap_cookie_tnew_dhp2, void **new_pvtp2);
17
18
20 Solaris DDI specific (Solaris DDI).
21
23 dhp An opaque mapping handle that the system uses to describe
24 the mapping.
25
26
27 pvtp Driver private mapping data.
28
29
30 off User offset within the logical device memory at which the
31 unmapping begins.
32
33
34 len Length (in bytes) of the memory being unmapped.
35
36
37 new_dhp1 The opaque mapping handle that the system uses to
38 describe the new region that ends at (off - 1) . new_dhp1
39 may be NULL.
40
41
42 new_pvtp1 A pointer to be filled in by the driver with the driver
43 private mapping data for the new region that ends at (off
44 - 1); ignored if new_dhp1 is NULL.
45
46
47 new_dhp2 The opaque mapping handle that the system uses to
48 describe the new region that begins at (off + len);
49 new_dhp2 may be NULL.
50
51
52 new_pvtp2 A pointer to be filled in by the driver with the driver
53 private mapping data for the new region that begins at
54 (off + len); ignored if new_dhp2 is NULL.
55
56
58 devmap_unmap() is called when the system removes the mapping in the
59 range [ off, off + len ], such as in the munmap(2) or exit(2) system
60 calls. Device drivers use devmap_unmap() to free up the resources allo‐
61 cated in devmap_map(9E).
62
63
64 dhp is the mapping handle that uniquely identifies the mapping. The
65 driver stores the mapping attributes in the driver's private data,
66 pvtp, when the mapping is created. See devmap_map(9E) for details.
67
68
69 off and len define the range to be affected by devmap_unmap(). This
70 range is within the boundary of the mapping described by dhp.
71
72
73 If the range [ off, off + len ] covers the entire mapping, the system
74 passes NULL to new_dhp1, new_pvtp1, new_dhp2, and new_pvtp2. The sys‐
75 tem expects device drivers to free all resources allocated for this
76 mapping.
77
78
79 If off is at the beginning of the mapping and len does not cover the
80 entire mapping, the system sets NULL to new_dhp1 and to new_pvtp1. The
81 system expects the drivers to allocate new driver private data for the
82 region that starts at off + len and to set *new_pvtp2 to point to it.
83 new_dhp2 is the mapping handle of the newly mapped object.
84
85
86 If off is not at the beginning of the mapping, but off + len is at the
87 end of the mapping the system passes NULL to new_dhp2 and new_pvtp2.
88 The system then expects the drivers to allocate new driver private data
89 for the region that begins at the beginning of the mapping (for exam‐
90 ple, stored in pvtp) and to set *new_pvtp1 to point to it. new_dhp1 is
91 the mapping handle of the newly mapped object.
92
93
94 The drivers should free up the driver private data, pvtp, previously
95 allocated in devmap_map(9E) before returning to the system.
96
98 Example 1 devmap_unmap() implementation
99
100 static void
101 xxdevmap_unmap(devmap_cookie_t dhp, void *pvtp, offset_t off,
102 size_t len, devmap_cookie_t new_dhp1, void **new_pvtp1,
103 devmap_cookie_t new_dhp2, void **new_pvtp2)
104 {
105 struct xxpvtdata *ptmp;
106 struct xxpvtdata *p = (struct xxpvtdata *)pvtp;
107 struct xx_softc *softc = p->softc;
108 mutex_enter(&softc->mutex);
109 /*
110 * If new_dhp1 is not NULL, create a new driver private data
111 * for the region from the beginning of old mapping to off.
112 */
113 if (new_dhp1 != NULL) {
114 ptmp = kmem_zalloc(sizeof (struct xxpvtdata), KM_SLEEP);
115 ptmp->dhp = new_dhp1;
116 ptmp->off = pvtp->off;
117 ptmp->len = off - pvtp->off;
118 *new_pvtp1 = ptmp;
119 }
120
121 /*
122 * If new_dhp2 is not NULL, create a new driver private data
123 * for the region from off+len to the end of the old mapping.
124 */
125 if (new_dhp2 != NULL) {
126 ptmp = kmem_zalloc(sizeof (struct xxpvtdata), KM_SLEEP);
127 ptmp->off = off + len;
128 ptmp->len = pvpt->len - (off + len - pvtp->off);
129 ptmp->dhp = new_dhp2;
130 *new_pvtp2 = ptmp;
131 }
132
133 /* Destroy the driver private data - Device dependent */
134 ...
135 kmem_free(pvtp, sizeof (struct xxpvtdata));
136 mutex_exit(&softc->mutex);
137 }
138
139
141 exit(2), munmap(2), devmap_map(9E), devmap_callback_ctl(9S)
142
143
144 Writing Device Drivers
145
146
147
148SunOS 5.11 21 Jan 1997 devmap_unmap(9E)