Skip to content

Commit c622b0c

Browse files
CopilotJohnAmadis
andcommitted
Document driver name resolution priority and device numbering mechanism
Co-authored-by: JohnAmadis <17320783+JohnAmadis@users.noreply.github.com>
1 parent 5bda391 commit c622b0c

1 file changed

Lines changed: 157 additions & 6 deletions

File tree

README.md

Lines changed: 157 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,18 +218,169 @@ stop_bits = 1
218218
4. **Driver Initialization**: The entire INI context is passed to the driver's `dmdrvi_create()` function
219219
5. **Device Mapping**: The driver is registered and becomes accessible through the filesystem
220220

221-
### Configuration File Naming
221+
### Driver Name Resolution
222222

223-
The filename (without `.ini` extension) can serve as a fallback driver name if `driver_name` is not specified in the file:
223+
DMDEVFS determines which driver module to load using a priority-based resolution mechanism. The driver name can be specified in three ways, checked in the following order:
224+
225+
#### 1. From INI File Content (Highest Priority)
226+
227+
The `driver_name` field in the `[main]` section explicitly specifies which driver to load:
224228

225229
```ini
226-
# File: my_custom_driver.ini
230+
# File: /etc/dmdevfs/storage.ini
227231
[main]
228-
# driver_name is optional if filename matches the module name
229-
parameter1 = value1
232+
driver_name = dmspiflash
233+
# ... other parameters
234+
```
235+
236+
This loads the `dmspiflash` driver module, regardless of the filename or directory.
237+
238+
#### 2. From Configuration Filename (Fallback)
239+
240+
If `driver_name` is not specified in the INI file, the basename of the configuration file (without `.ini` extension) is used:
241+
242+
```ini
243+
# File: /etc/dmdevfs/dmi2ceeprom.ini
244+
[main]
245+
# No driver_name specified
246+
i2c_bus = 0
247+
device_address = 0x50
248+
```
249+
250+
This loads the `dmi2ceeprom` driver module based on the filename.
251+
252+
#### 3. From Directory Name (Hierarchical Configuration)
253+
254+
When configuration files are organized in subdirectories, the directory name can be passed to nested configurations:
255+
256+
```
257+
/etc/dmdevfs/
258+
└── dmspiflash/
259+
├── device0.ini # Uses "dmspiflash" from directory name
260+
└── device1.ini # Uses "dmspiflash" from directory name
261+
```
262+
263+
Each `.ini` file in the `dmspiflash/` directory will use `dmspiflash` as the default driver name unless overridden by the `driver_name` field in the file itself.
264+
265+
**Example of Combined Usage:**
266+
267+
```
268+
/etc/dmdevfs/
269+
├── flash.ini # Uses filename: "flash" driver
270+
├── spi/
271+
│ ├── device0.ini # Uses directory: "spi" driver
272+
│ └── device1.ini # Uses directory: "spi" driver
273+
└── custom.ini # Contains driver_name=dmi2ceeprom in file
274+
```
275+
276+
### Device Numbering and Path Generation
277+
278+
When a driver is initialized through its `dmdrvi_create()` function, it returns a device number structure (`dev_num`) that controls how the driver appears in the filesystem. This mechanism allows multiple instances of the same driver with different configurations.
279+
280+
#### Device Number Structure
281+
282+
The device number consists of:
283+
- **major**: Primary device identifier (typically for device type or bus)
284+
- **minor**: Secondary device identifier (typically for device instance)
285+
- **flags**: Indicates which numbers are provided (`DMDRVI_NUM_MAJOR`, `DMDRVI_NUM_MINOR`)
286+
287+
#### Path Generation Rules
288+
289+
The resulting filesystem path depends on which device numbers the driver provides:
290+
291+
| Major | Minor | Resulting Path | Example |
292+
|-------|-------|----------------|---------|
293+
||| `<driver_name><major>/<minor>` | `spiflash0/1` |
294+
||| `<driver_name>x/<minor>` | `spiflashx/0` |
295+
||| `<driver_name><major>` | `spiflash0` |
296+
||| `<driver_name>` | `spiflash` |
297+
298+
#### Examples
299+
300+
**Example 1: Both Major and Minor Provided**
301+
302+
Configuration file: `/etc/dmdevfs/spi0.ini`
303+
```ini
304+
[main]
305+
driver_name = dmspiflash
306+
spi_bus = 0 # Driver uses this to set major=0
307+
chip_select = 1 # Driver uses this to set minor=1
230308
```
231309

232-
In this case, DMDEVFS will attempt to load a module named `my_custom_driver`.
310+
Resulting path: `/mnt/dmspiflash0/1` (assuming mounted at `/mnt`)
311+
312+
**Example 2: Only Minor Provided**
313+
314+
Configuration file: `/etc/dmdevfs/eeprom.ini`
315+
```ini
316+
[main]
317+
driver_name = dmi2ceeprom
318+
device_address = 0x50 # Driver uses this to set minor=0
319+
```
320+
321+
Resulting path: `/mnt/dmi2ceepromx/0`
322+
323+
**Example 3: Only Major Provided**
324+
325+
Configuration file: `/etc/dmdevfs/uart.ini`
326+
```ini
327+
[main]
328+
driver_name = dmuartstorage
329+
uart_port = 2 # Driver uses this to set major=2
330+
```
331+
332+
Resulting path: `/mnt/dmuartstorage2`
333+
334+
**Example 4: No Device Numbers**
335+
336+
Configuration file: `/etc/dmdevfs/generic.ini`
337+
```ini
338+
[main]
339+
driver_name = dmgenericdriver
340+
```
341+
342+
Resulting path: `/mnt/dmgenericdriver`
343+
344+
#### Multiple Device Instances
345+
346+
You can configure multiple instances of the same driver by using separate configuration files:
347+
348+
```
349+
/etc/dmdevfs/
350+
├── spi_flash0.ini # major=0, minor=0 → /mnt/dmspiflash0/0
351+
├── spi_flash1.ini # major=0, minor=1 → /mnt/dmspiflash0/1
352+
└── spi_flash2.ini # major=1, minor=0 → /mnt/dmspiflash1/0
353+
```
354+
355+
Or using hierarchical organization:
356+
357+
```
358+
/etc/dmdevfs/dmspiflash/
359+
├── bus0_cs0.ini # major=0, minor=0 → /mnt/dmspiflash0/0
360+
├── bus0_cs1.ini # major=0, minor=1 → /mnt/dmspiflash0/1
361+
└── bus1_cs0.ini # major=1, minor=0 → /mnt/dmspiflash1/0
362+
```
363+
364+
#### Understanding the 'x' Notation
365+
366+
When only a minor number is provided (major not set), the path uses `x` as a placeholder. This is useful when the driver doesn't use a major/minor hierarchy but still wants to enumerate devices:
367+
368+
```
369+
/mnt/dmspiflashx/0
370+
/mnt/dmspiflashx/1
371+
/mnt/dmspiflashx/2
372+
```
373+
374+
This convention keeps paths consistent and prevents naming collisions.
375+
376+
#### Driver Implementation Notes
377+
378+
The device numbers are determined by the driver itself based on the configuration parameters. For example:
379+
- An SPI flash driver might use `spi_bus` as the major number and `chip_select` as the minor number
380+
- An I2C driver might use only the `device_address` as the minor number
381+
- A generic driver might not use device numbers at all
382+
383+
Consult your specific driver's documentation to understand how it uses configuration parameters to set device numbers.
233384

234385
### Best Practices
235386

0 commit comments

Comments
 (0)