Annotation of coherent/f/etc/conf/streams/src/devno.c, revision 1.1.1.1

1.1       root        1: #define        _DDI_DKI        1
                      2: #define        _SYSV4          1
                      3: 
                      4: /*
                      5:  * Routines for manipulating device numbers.
                      6:  *
                      7:  * System V defines "dev_t" as 32-bit, which makes some things problematic
                      8:  * when attempting to run SVR4 drivers in an iBCS2 environment. The concept
                      9:  * of external and internal numbers, introduced at the same time as the 32-
                     10:  * bit "dev_t", provides an effective solution.
                     11:  *
                     12:  * This is of primary importance to clone devices which may want to support
                     13:  * more than 256 connections, but any driver which wants or needs to encode
                     14:  * more that 8 bits of information in the minor number may also benefit from
                     15:  * use of the external/internal mapping regime.
                     16:  */
                     17: 
                     18: /*
                     19:  *-IMPORTS:
                     20:  *     <sys/types.h>
                     21:  *             dev_t
                     22:  *     <limits.h>
                     23:  *             CHAR_BIT
                     24:  */
                     25: 
                     26: #include <sys/types.h>
                     27: #include <limits.h>
                     28: 
                     29: /*
                     30:  * Define this symbol to make the code in this module ignore the _max_minor,
                     31:  * _major [], and _minor [] configuration tables, and simply map internal and
                     32:  * external major and minor numbers one-to-one.
                     33:  */
                     34: /* #define ONE_TO_ONE */
                     35: 
                     36: /*
                     37:  * If we are dealing with a situation where we are trying to run DDI/DKI code
                     38:  * side-by-side with code that uses a different "dev_t", we rely on a layer
                     39:  * that can may the pre-SVR4 or alien calling sequence for the DDI/DKI entry
                     40:  * points. This code must deal with converting the old-style "dev_t" to a
                     41:  * new-style "dev_t" and vice-versa.
                     42:  *
                     43:  * In particular, if a device generates a minor number outside the range of
                     44:  * precision of the old-style system, the mapping layer must use these
                     45:  * functions to select an appropriate major number to overflow to.
                     46:  */
                     47: 
                     48: #define        DSHIFT                  (sizeof (dev_t) * CHAR_BIT / 2)
                     49: 
                     50: #define        GETEMAJOR(dev)          ((major_t) ((dev) >> DSHIFT))
                     51: #define        GETEMINOR(dev)          ((minor_t) ((dev) & ~ (1L << DSHIFT)))
                     52: #define        MAKEDEVICE(maj,min)     (((dev_t) (maj) << DSHIFT) + (min))
                     53: 
                     54: 
                     55: /*
                     56:  * The following external reference is to a table generated by the kernel
                     57:  * configuration process for all the devices configured in the system. It
                     58:  * defines a many-to-one mapping between external and internal major device
                     59:  * numbers.
                     60:  *
                     61:  * This mapping can also affect internal device numbers; for instance,
                     62:  * external major device 10, minor 5 might map to internal 2, minor 30.
                     63:  */
                     64: 
                     65: #ifndef        ONE_TO_ONE
                     66: 
                     67: extern major_t _maxmajor;
                     68: extern major_t _major [];      /* internal major number for external major */
                     69: extern minor_t _minor [];      /* value added to external minor number */
                     70: 
                     71: #endif
                     72: 
                     73: /*
                     74:  *-STATUS:
                     75:  *     DDI/DKI
                     76:  *
                     77:  *-NAME:
                     78:  *     etoimajor       Convert external to internal major device number.
                     79:  *
                     80:  *-SYNOPSIS:
                     81:  *     #include <sys/types.h>
                     82:  *     #include <sys/ddi.h>
                     83:  *
                     84:  *     major_t etoimajor (major_t emaj);
                     85:  *
                     86:  *-ARGUMENTS:
                     87:  *     emaj            External major number.
                     88:  *
                     89:  *-DESCRIPTION:
                     90:  *     etoimajor () converts the external major number (emaj) to an internal
                     91:  *     major number. See getemajor () for a description of external and
                     92:  *     internal major numbers.
                     93:  *
                     94:  *-RETURN VALUE:
                     95:  *     etoimajor () returns the internal major number or NODEV if the
                     96:  *     external major number is not valid.
                     97:  *
                     98:  *-LEVEL:
                     99:  *     Base or interrupt.
                    100:  *
                    101:  *-NOTES:
                    102:  *     Does not sleep.
                    103:  *
                    104:  *     Driver-defined basic locks, read/write locks, and sleep locks may be
                    105:  *     held across calls to this function.
                    106:  *
                    107:  *-SEE ALSO:
                    108:  *     getemajor (), geteminor (), getmajor (), getminor (), itoemajor (),
                    109:  *     makedevice ().
                    110:  */
                    111: 
                    112: #if    __USE_PROTO__
                    113: major_t (etoimajor) (major_t emaj)
                    114: #else
                    115: major_t
                    116: etoimajor __ARGS ((emaj))
                    117: major_t                emaj;
                    118: #endif
                    119: {
                    120: #ifdef ONE_TO_ONE
                    121:        return emaj;
                    122: #else
                    123:        return (emaj >= _maxmajor ? NODEV : _major [emaj]);
                    124: #endif
                    125: }
                    126: 
                    127: 
                    128: /*
                    129:  *-STATUS:
                    130:  *     DDI/DKI
                    131:  *
                    132:  *-NAME:
                    133:  *     getemajor       Get external major device number.
                    134:  *
                    135:  *-SYNOPSIS:
                    136:  *     #include <sys/types.h>
                    137:  *     #include <sys/ddi.h>
                    138:  *
                    139:  *     major_t getemajor (dev_t dev);
                    140:  *
                    141:  *-ARGUMENTS:
                    142:  *     dev             External device number.
                    143:  *
                    144:  *-DESCRIPTION:
                    145:  *     getemajor () returns the external major number given a device number,
                    146:  *     "dev". External major numbers are visible to the user. Internal major
                    147:  *     numbers are only visible in the kernel. Since the range of major
                    148:  *     numbers may be large and sparsely populated, the kernel keeps a
                    149:  *     mapping between external and internal major numbers to save space.
                    150:  *
                    151:  *     All driver entry points are passed device numbers using external
                    152:  *     major numbers.
                    153:  *
                    154:  *     Usually, a driver with more than one external major number will have
                    155:  *     only one internal major number. However, some system implementations
                    156:  *     map one-to-one between internal and external major numbers. Here, the
                    157:  *     internal major number is the same as the external major number and the
                    158:  *     driver may have more than one internal major number.
                    159:  *
                    160:  *-RETURN VALUE:
                    161:  *     The external major number.
                    162:  *
                    163:  *-LEVEL:
                    164:  *     Base or interrupt.
                    165:  *
                    166:  *-NOTES:
                    167:  *     Does not sleep.
                    168:  *
                    169:  *     Driver-defined basic locks, read/write locks, and sleep locks may be
                    170:  *     held across calls to this function.
                    171:  *
                    172:  *-SEE ALSO:
                    173:  *     etoimajor (), geteminor (), getmajor (), getminor (), makedevice ().
                    174:  */
                    175: 
                    176: #if    __USE_PROTO__
                    177: major_t (getemajor) (n_dev_t dev)
                    178: #else
                    179: major_t
                    180: getemajor __ARGS ((dev))
                    181: n_dev_t                dev;
                    182: #endif
                    183: {
                    184:        return GETEMAJOR (dev);
                    185: }
                    186: 
                    187: 
                    188: /*
                    189:  *-STATUS:
                    190:  *     DDI/DKI
                    191:  *
                    192:  *-NAME:
                    193:  *     geteminor       Get external minor device number.
                    194:  *
                    195:  *-SYNOPSIS:
                    196:  *     #include <sys/types.h>
                    197:  *     #include <sys/ddi.h>
                    198:  *
                    199:  *     minor_t geteminor (dev_t dev);
                    200:  *
                    201:  *-ARGUMENTS:
                    202:  *     dev             External device number.
                    203:  *
                    204:  *-DESCRIPTION:
                    205:  *     geteminor () returns the external minor number given a device number,
                    206:  *     "dev". External minor numbers are visible to the user. Internal minor
                    207:  *     numbers are only visible in the kernel. Since a driver can support
                    208:  *     more than one external major device that maps to the same internal
                    209:  *     major device, the kernel keeps a mapping between external minor
                    210:  *     numbers and internal minor numbers to allow drivers to index arrays
                    211:  *     more easily. For example, a driver may support two devices, each with
                    212:  *     five minor numbers. The user may see each set of minor numbers
                    213:  *     numbered from zero to four, but the driver sees them as one set of
                    214:  *     minor numbers numbered zero to nine.
                    215:  *
                    216:  *     All driver entry points are passed device numbers using external minor
                    217:  *     numbers.
                    218:  *
                    219:  *     Systems that map external major numbers one-to-one with internal major
                    220:  *     numbers also map external minor numbers one-to-one with internal minor
                    221:  *     numbers.
                    222:  *
                    223:  *-RETURN VALUE:
                    224:  *     The external minor number.
                    225:  *
                    226:  *-LEVEL:
                    227:  *     Base or interrupt.
                    228:  *
                    229:  *-NOTES:
                    230:  *     Does not sleep.
                    231:  *
                    232:  *     Driver-defined basic locks, read/write locks, and sleep locks may be
                    233:  *     held across calls to this function.
                    234:  *
                    235:  *-SEE ALSO:
                    236:  *     etoimajor (), getemajor (), getmajor (), getminor (), makedevice ()
                    237:  */
                    238: 
                    239: #if    __USE_PROTO__
                    240: minor_t (geteminor) (n_dev_t dev)
                    241: #else
                    242: minor_t
                    243: geteminor __ARGS ((dev))
                    244: n_dev_t                dev;
                    245: #endif
                    246: {
                    247:        return GETEMINOR (dev);
                    248: }
                    249: 
                    250: 
                    251: /*
                    252:  *-STATUS:
                    253:  *     DDI/DKI
                    254:  *
                    255:  *-NAME:
                    256:  *     getmajor        Get internal major device number.
                    257:  *
                    258:  *-SYNOPSIS:
                    259:  *     #include <sys/types.h>
                    260:  *     #include <sys/ddi.h>
                    261:  *
                    262:  *     major_t getemajor (dev_t dev);
                    263:  *
                    264:  *-ARGUMENTS:
                    265:  *     dev             Device number.
                    266:  *
                    267:  *-DESCRIPTION:
                    268:  *     The getmajor () function extracts the internal major number from a
                    269:  *     device number. See getemajor () for an explanation of external and
                    270:  *     internal major numbers.
                    271:  *
                    272:  *-RETURN VALUE:
                    273:  *     The internal major number.
                    274:  *
                    275:  *-LEVEL:
                    276:  *     Base or interrupt.
                    277:  *
                    278:  *-NOTES:
                    279:  *     No validity checking is performed. If "dev" is invalid, an invalid
                    280:  *     number is returned.
                    281:  *
                    282:  *     Does not sleep.
                    283:  *
                    284:  *     Driver-defined basic locks, read/write locks, and sleep locks may be
                    285:  *     held across calls to this function.
                    286:  *
                    287:  *-SEE ALSO:
                    288:  *     etoimajor (), getemajor (), geteminor (), getminor (), makedevice ()
                    289:  */
                    290: 
                    291: #if    __USE_PROTO__
                    292: major_t (getmajor) (n_dev_t dev)
                    293: #else
                    294: major_t
                    295: getmajor __ARGS ((dev))
                    296: n_dev_t                dev;
                    297: #endif
                    298: {
                    299: #ifdef ONE_TO_ONE
                    300:        return GETEMAJOR (dev);
                    301: #else
                    302:        return _major [GETEMAJOR (dev)];
                    303: #endif
                    304: }
                    305: 
                    306: 
                    307: /*
                    308:  *-STATUS:
                    309:  *     DDI/DKI
                    310:  *
                    311:  *-NAME:
                    312:  *     getminor        Get internal minor device number.
                    313:  *
                    314:  *-SYNOPSIS:
                    315:  *     #include <sys/types.h>
                    316:  *     #include <sys/ddi.h>
                    317:  *
                    318:  *     minor_t getminor (dev_t dev);
                    319:  *
                    320:  *-ARGUMENTS:
                    321:  *     dev             Device number.
                    322:  *
                    323:  *-DESCRIPTION:
                    324:  *     The getminor () function extracts the internal minor number from a
                    325:  *     device number. See getemajor () for an explanation of external and
                    326:  *     internal major numbers.
                    327:  *
                    328:  *-RETURN VALUE:
                    329:  *     The internal minor number.
                    330:  *
                    331:  *-LEVEL:
                    332:  *     Base or interrupt.
                    333:  *
                    334:  *-NOTES:
                    335:  *     No validity checking is performed. If "dev" is invalid, an invalid
                    336:  *     number is returned.
                    337:  *
                    338:  *     Does not sleep.
                    339:  *
                    340:  *     Driver-defined basic locks, read/write locks, and sleep locks may be
                    341:  *     held across calls to this function.
                    342:  *
                    343:  *-SEE ALSO:
                    344:  *     etoimajor (), getemajor (), geteminor (), getmajor (), makedevice ()
                    345:  */
                    346: 
                    347: #if    __USE_PROTO__
                    348: minor_t (getminor) (n_dev_t dev)
                    349: #else
                    350: minor_t
                    351: getminor __ARGS ((dev))
                    352: n_dev_t                dev;
                    353: #endif
                    354: {
                    355: #ifdef ONE_TO_ONE
                    356:        return GETEMINOR (dev);
                    357: #else
                    358:        return GETEMINOR (dev) + _minor [GETEMAJOR (dev)];
                    359: #endif
                    360: }
                    361: 
                    362: 
                    363: /*
                    364:  *-STATUS:
                    365:  *     DDI/DKI
                    366:  *
                    367:  *-NAME:
                    368:  *     itoemajor       Convert internal to external major number.
                    369:  *
                    370:  *-SYNOPSIS:
                    371:  *     #include <sys/types.h>
                    372:  *     #include <sys/ddi.h>
                    373:  *
                    374:  *     major_t itoemajor (major_t imaj, major_t prevemaj);
                    375:  *
                    376:  *-ARGUMENTS:
                    377:  *     imaj            Internal major number.
                    378:  *
                    379:  *     prevemaj        Most recently obtained external major number (or
                    380:  *                     NODEV, if this is the first time the function has been
                    381:  *                     called).
                    382:  *
                    383:  *-DESCRIPTION:
                    384:  *     itoemajor () converts the internal major number to the external major
                    385:  *     number. The external-to-internal major number mapping can be many-to-
                    386:  *     one, and so any internal major number may correspond to more than one
                    387:  *     external major number. By repeatedly invoking this function, the
                    388:  *     driver can obtain all possible external major number values. See
                    389:  *     getemajor () for an explanation of external and internal major
                    390:  *     numbers.
                    391:  *
                    392:  *-RETURN VALUE:
                    393:  *     External major number, or NODEV if all have been searched.
                    394:  *
                    395:  *-LEVEL:
                    396:  *     Base or interrupt.
                    397:  *
                    398:  *-NOTES:
                    399:  *     Does not sleep.
                    400:  *
                    401:  *     Driver-defined basic locks, read/write locks, and sleep locks may be
                    402:  *     held across calls to this function.
                    403:  *
                    404:  *-SEE ALSO:
                    405:  *     etoimajor (), getemajor (), geteminor (), getmajor (), getminor (),
                    406:  *     makedevice ()
                    407:  */
                    408: 
                    409: #if    __USE_PROTO__
                    410: major_t (itoemajor) (major_t imaj, major_t prevemaj)
                    411: #else
                    412: major_t
                    413: itoemajor __ARGS ((imaj, prevemaj))
                    414: major_t                imaj;
                    415: major_t                prevemaj;
                    416: #endif
                    417: {
                    418: #ifdef ONE_TO_ONE
                    419:        return prevemaj == NODEV ? imaj : NODEV;
                    420: #else
                    421:        if (prevemaj == NODEV)
                    422:                prevemaj = 0;
                    423:        else
                    424:                prevemaj ++;
                    425: 
                    426:        while (prevemaj ++ < _maxmajor)
                    427:                if (_major [prevemaj] == imaj)
                    428:                        return  prevemaj;
                    429: 
                    430:        return NODEV;
                    431: #endif
                    432: }
                    433: 
                    434: 
                    435: /*
                    436:  *-STATUS:
                    437:  *     DDI/DKI
                    438:  *
                    439:  *-NAME:
                    440:  *     makedevice      Make device number from major and minor numbers.
                    441:  *
                    442:  *-SYNOPSIS:
                    443:  *     #include <sys/types.h>
                    444:  *     #include <sys/ddi.h>
                    445:  *
                    446:  *     dev_t makedevice (major_t majnum, minor_t minnum);
                    447:  *
                    448:  *-ARGUMENTS:
                    449:  *     majnum          Major number.
                    450:  *
                    451:  *     minnum          Minor number.
                    452:  *
                    453:  *-DESCRIPTION:
                    454:  *     The makedevice () function creates a device number from a major and
                    455:  *     minor device number. makedevice () should be used to create device
                    456:  *     numbers so that the driver will port easily to releases that treat
                    457:  *     device numbers differently.
                    458:  *
                    459:  *-RETURN VALUE:
                    460:  *     The device number, containing both the major number and the minor
                    461:  *     number, is returned. No validation of the major or number numbers is
                    462:  *     performed.
                    463:  *
                    464:  *-LEVEL:
                    465:  *     Base or interrupt.
                    466:  *
                    467:  *-NOTES:
                    468:  *     Does not sleep.
                    469:  *
                    470:  *     Driver-defined basic locks, read/write locks, and sleep locks may be
                    471:  *     held across calls to this function.
                    472:  *
                    473:  *-SEE ALSO:
                    474:  *     getemajor (), geteminor (), getmajor (), getminor ()
                    475:  */
                    476: 
                    477: #if    __USE_PROTO__
                    478: n_dev_t (makedevice) (major_t majnum, minor_t minnum)
                    479: #else
                    480: n_dev_t
                    481: makedevice __ARGS ((majnum, minnum))
                    482: major_t                majnum;
                    483: minor_t                minnum;
                    484: #endif
                    485: {
                    486:        return MAKEDEVICE (majnum, minnum);
                    487: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.