@@ -42,6 +42,8 @@ import (
42
42
"io/fs"
43
43
"log"
44
44
"os"
45
+ "path/filepath"
46
+ "strconv"
45
47
46
48
"golang.org/x/sys/unix"
47
49
)
@@ -78,36 +80,36 @@ type genOptions struct {
78
80
}
79
81
80
82
func addSysfsDriTree (root string , opts * genOptions , i int ) error {
81
- card := cardBase + i
82
- base := fmt . Sprintf ( "%s/ class/drm/card%d " , root , card )
83
+ card := fmt . Sprintf ( "card%d" , cardBase + i )
84
+ base := filepath . Join ( root , " class" , "drm" , card )
83
85
84
86
if err := os .MkdirAll (base , dirMode ); err != nil {
85
87
return err
86
88
}
87
89
opts .dirs ++
88
90
89
- data := []byte (fmt . Sprintf ( "%d" , opts .DevMemSize ))
90
- file := fmt . Sprintf ( "%s/ lmem_total_bytes", base )
91
+ data := []byte (strconv . Itoa ( opts .DevMemSize ))
92
+ file := filepath . Join ( base , " lmem_total_bytes" )
91
93
92
94
if err := os .WriteFile (file , data , fileMode ); err != nil {
93
95
return err
94
96
}
95
97
opts .files ++
96
98
97
- path := fmt . Sprintf ( "%s/ device/drm/card%d " , base , card )
99
+ path := filepath . Join ( base , " device" , "drm" , card )
98
100
if err := os .MkdirAll (path , dirMode ); err != nil {
99
101
return err
100
102
}
101
103
opts .dirs ++
102
104
103
- path = fmt . Sprintf ( "%s/ device/ drm/ renderD%d" , base , renderBase + i )
105
+ path = filepath . Join ( base , " device" , " drm" , fmt . Sprintf ( " renderD%d" , renderBase + i ) )
104
106
if err := os .Mkdir (path , dirMode ); err != nil {
105
107
return err
106
108
}
107
109
opts .dirs ++
108
110
109
111
data = []byte ("0x8086" )
110
- file = fmt . Sprintf ( "%s/ device/vendor " , base )
112
+ file = filepath . Join ( base , " device" , "vendor" )
111
113
112
114
if err := os .WriteFile (file , data , fileMode ); err != nil {
113
115
return err
@@ -119,17 +121,17 @@ func addSysfsDriTree(root string, opts *genOptions, i int) error {
119
121
node = i / opts .DevsPerNode
120
122
}
121
123
122
- data = []byte (fmt . Sprintf ( "%d" , node ))
123
- file = fmt . Sprintf ( "%s/ device/numa_node " , base )
124
+ data = []byte (strconv . Itoa ( node ))
125
+ file = filepath . Join ( base , " device" , "numa_node" )
124
126
125
127
if err := os .WriteFile (file , data , fileMode ); err != nil {
126
128
return err
127
129
}
128
130
opts .files ++
129
131
130
132
if opts .VfsPerPf > 0 && i % (opts .VfsPerPf + 1 ) == 0 {
131
- data = []byte (fmt . Sprintf ( "%d" , opts .VfsPerPf ))
132
- file = fmt . Sprintf ( "%s/ device/sriov_numvfs " , base )
133
+ data = []byte (strconv . Itoa ( opts .VfsPerPf ))
134
+ file = filepath . Join ( base , " device" , "sriov_numvfs" )
133
135
134
136
if err := os .WriteFile (file , data , fileMode ); err != nil {
135
137
return err
@@ -138,7 +140,7 @@ func addSysfsDriTree(root string, opts *genOptions, i int) error {
138
140
}
139
141
140
142
for tile := 0 ; tile < opts .TilesPerDev ; tile ++ {
141
- path := fmt .Sprintf ("%s/gt/gt %d" , base , tile )
143
+ path := filepath . Join ( base , "gt" , fmt .Sprintf ("gt %d" , tile ) )
142
144
if err := os .MkdirAll (path , dirMode ); err != nil {
143
145
return err
144
146
}
@@ -148,24 +150,44 @@ func addSysfsDriTree(root string, opts *genOptions, i int) error {
148
150
return nil
149
151
}
150
152
151
- func addDevfsDriTree (root string , opts * genOptions , i int ) error {
152
- base := fmt .Sprintf ("%s/dri" , root )
153
+ func addSysfsBusTree (root string , opts * genOptions , i int ) error {
154
+ pciName := fmt .Sprintf ("0000:00:0%d.0" , i )
155
+ base := filepath .Join (root , "bus" , "pci" , "drivers" , "i915" , pciName )
156
+
153
157
if err := os .MkdirAll (base , dirMode ); err != nil {
154
158
return err
155
159
}
156
160
opts .dirs ++
157
161
162
+ data := []byte ("0x4905" )
163
+ file := filepath .Join (base , "device" )
164
+
165
+ if err := os .WriteFile (file , data , fileMode ); err != nil {
166
+ return err
167
+ }
168
+ opts .files ++
169
+
170
+ drm := filepath .Join (base , "drm" )
171
+ if err := os .MkdirAll (drm , dirMode ); err != nil {
172
+ return err
173
+ }
174
+ opts .dirs ++
175
+
176
+ return addDeviceNodes (drm , opts , i )
177
+ }
178
+
179
+ func addDeviceNodes (base string , opts * genOptions , i int ) error {
158
180
mode := uint32 (fileMode | devNullType )
159
181
devid := int (unix .Mkdev (uint32 (devNullMajor ), uint32 (devNullMinor )))
160
182
161
- file := fmt .Sprintf ("%s/ card%d" , base , cardBase + i )
183
+ file := filepath . Join ( base , fmt .Sprintf ("card%d" , cardBase + i ) )
162
184
if err := unix .Mknod (file , mode , devid ); err != nil {
163
185
return fmt .Errorf ("NULL device (%d:%d) node creation failed for '%s': %w" ,
164
186
devNullMajor , devNullMinor , file , err )
165
187
}
166
188
opts .devs ++
167
189
168
- file = fmt .Sprintf ("%s/ renderD%d" , base , renderBase + i )
190
+ file = filepath . Join ( base , fmt .Sprintf ("renderD%d" , renderBase + i ) )
169
191
if err := unix .Mknod (file , mode , devid ); err != nil {
170
192
return fmt .Errorf ("NULL device (%d:%d) node creation failed for '%s': %w" ,
171
193
devNullMajor , devNullMinor , file , err )
@@ -175,14 +197,24 @@ func addDevfsDriTree(root string, opts *genOptions, i int) error {
175
197
return nil
176
198
}
177
199
200
+ func addDevfsDriTree (root string , opts * genOptions , i int ) error {
201
+ base := filepath .Join (root , "dri" )
202
+ if err := os .MkdirAll (base , dirMode ); err != nil {
203
+ return err
204
+ }
205
+ opts .dirs ++
206
+
207
+ return addDeviceNodes (base , opts , i )
208
+ }
209
+
178
210
func addDebugfsDriTree (root string , opts * genOptions , i int ) error {
179
- base := fmt . Sprintf ( "%s/ kernel/ debug/dri/%d " , root , i )
211
+ base := filepath . Join ( root , " kernel" , " debug" , "dri" , strconv . Itoa ( i ) )
180
212
if err := os .MkdirAll (base , dirMode ); err != nil {
181
213
return err
182
214
}
183
215
opts .dirs ++
184
216
185
- path := fmt . Sprintf ( "%s/ i915_capabilities", base )
217
+ path := filepath . Join ( base , " i915_capabilities" )
186
218
f , err := os .OpenFile (path , os .O_WRONLY | os .O_CREATE | os .O_EXCL , fileMode )
187
219
188
220
if err != nil {
@@ -212,8 +244,8 @@ func removeExistingDir(path, name string) {
212
244
return
213
245
}
214
246
215
- if name == "sysfs" && len (entries ) > 2 {
216
- log .Fatalf ("ERROR: >2 entries in '%s' - real sysfs?" , path )
247
+ if name == "sysfs" && len (entries ) > 3 {
248
+ log .Fatalf ("ERROR: >3 entries in '%s' - real sysfs?" , path )
217
249
}
218
250
219
251
if name == "devfs" && (entries [0 ].Name () != "dri" || len (entries ) > 1 ) {
@@ -251,6 +283,10 @@ func generateDriFiles(opts genOptions) {
251
283
if err := addDevfsDriTree (devfsPath , & opts , i ); err != nil {
252
284
log .Fatalf ("ERROR: dev-%d devfs tree generation failed: %v" , i , err )
253
285
}
286
+
287
+ if err := addSysfsBusTree (sysfsPath , & opts , i ); err != nil {
288
+ log .Fatalf ("ERROR: dev-%d sysfs bus tree generation failed: %v" , i , err )
289
+ }
254
290
}
255
291
log .Printf ("Done, created %d dirs, %d devices and %d files." , opts .dirs , opts .devs , opts .files )
256
292
}
0 commit comments