OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [rc203soc/] [sw/] [uClinux/] [include/] [linux/] [kdev_t.h] - Diff between revs 1765 and 1782

Only display areas with differences | Details | Blame | View Log

Rev 1765 Rev 1782
#ifndef _LINUX_KDEV_T_H
#ifndef _LINUX_KDEV_T_H
#define _LINUX_KDEV_T_H
#define _LINUX_KDEV_T_H
#ifdef __KERNEL__
#ifdef __KERNEL__
/*
/*
As a preparation for the introduction of larger device numbers,
As a preparation for the introduction of larger device numbers,
we introduce a type kdev_t to hold them. No information about
we introduce a type kdev_t to hold them. No information about
this type is known outside of this include file.
this type is known outside of this include file.
 
 
Objects of type kdev_t designate a device. Outside of the kernel
Objects of type kdev_t designate a device. Outside of the kernel
the corresponding things are objects of type dev_t - usually an
the corresponding things are objects of type dev_t - usually an
integral type with the device major and minor in the high and low
integral type with the device major and minor in the high and low
bits, respectively. Conversion is done by
bits, respectively. Conversion is done by
 
 
extern kdev_t to_kdev_t(int);
extern kdev_t to_kdev_t(int);
 
 
It is up to the various file systems to decide how objects of type
It is up to the various file systems to decide how objects of type
dev_t are stored on disk.
dev_t are stored on disk.
The only other point of contact between kernel and outside world
The only other point of contact between kernel and outside world
are the system calls stat and mknod, new versions of which will
are the system calls stat and mknod, new versions of which will
eventually have to be used in libc.
eventually have to be used in libc.
 
 
[Unfortunately, the floppy control ioctls fail to hide the internal
[Unfortunately, the floppy control ioctls fail to hide the internal
kernel structures, and the fd_device field of a struct floppy_drive_struct
kernel structures, and the fd_device field of a struct floppy_drive_struct
is user-visible. So, it remains a dev_t for the moment, with some ugly
is user-visible. So, it remains a dev_t for the moment, with some ugly
conversions in floppy.c.]
conversions in floppy.c.]
 
 
Inside the kernel, we aim for a kdev_t type that is a pointer
Inside the kernel, we aim for a kdev_t type that is a pointer
to a structure with information about the device (like major,
to a structure with information about the device (like major,
minor, size, blocksize, sectorsize, name, read-only flag,
minor, size, blocksize, sectorsize, name, read-only flag,
struct file_operations etc.).
struct file_operations etc.).
 
 
However, for the time being we let kdev_t be almost the same as dev_t:
However, for the time being we let kdev_t be almost the same as dev_t:
 
 
typedef struct { unsigned short major, minor; } kdev_t;
typedef struct { unsigned short major, minor; } kdev_t;
 
 
Admissible operations on an object of type kdev_t:
Admissible operations on an object of type kdev_t:
- passing it along
- passing it along
- comparing it for equality with another such object
- comparing it for equality with another such object
- storing it in ROOT_DEV, inode->i_dev, inode->i_rdev, sb->s_dev,
- storing it in ROOT_DEV, inode->i_dev, inode->i_rdev, sb->s_dev,
  bh->b_dev, req->rq_dev, de->dc_dev, tty->device
  bh->b_dev, req->rq_dev, de->dc_dev, tty->device
- using its bit pattern as argument in a hash function
- using its bit pattern as argument in a hash function
- finding its major and minor
- finding its major and minor
- complaining about it
- complaining about it
 
 
An object of type kdev_t is created only by the function MKDEV(),
An object of type kdev_t is created only by the function MKDEV(),
with the single exception of the constant 0 (no device).
with the single exception of the constant 0 (no device).
 
 
Right now the other information mentioned above is usually found
Right now the other information mentioned above is usually found
in static arrays indexed by major or major,minor.
in static arrays indexed by major or major,minor.
 
 
An obstacle to immediately using
An obstacle to immediately using
    typedef struct { ... (* lots of information *) } *kdev_t
    typedef struct { ... (* lots of information *) } *kdev_t
is the case of mknod used to create a block device that the
is the case of mknod used to create a block device that the
kernel doesn't know about at present (but first learns about
kernel doesn't know about at present (but first learns about
when some module is inserted).
when some module is inserted).
 
 
aeb - 950811
aeb - 950811
*/
*/
 
 
/* Since MINOR(dev) is used as index in static arrays,
/* Since MINOR(dev) is used as index in static arrays,
   the kernel is not quite ready yet for larger minors.
   the kernel is not quite ready yet for larger minors.
   However, everything runs fine with an arbitrary kdev_t type. */
   However, everything runs fine with an arbitrary kdev_t type. */
 
 
#define MINORBITS       8
#define MINORBITS       8
#define MINORMASK       ((1<<MINORBITS) - 1)
#define MINORMASK       ((1<<MINORBITS) - 1)
 
 
/* SIMON I won't fuck with this one */
/* SIMON I won't fuck with this one */
/*typedef unsigned short kdev_t;*/
/*typedef unsigned short kdev_t;*/
typedef int kdev_t;
typedef int kdev_t;
 
 
#define MAJOR(dev)      ((dev) >> MINORBITS)
#define MAJOR(dev)      ((dev) >> MINORBITS)
#define MINOR(dev)      ((dev) & MINORMASK)
#define MINOR(dev)      ((dev) & MINORMASK)
#define HASHDEV(dev)    (dev)
#define HASHDEV(dev)    (dev)
#define NODEV           0
#define NODEV           0
#define MKDEV(ma,mi)    (((ma) << MINORBITS) | (mi))
#define MKDEV(ma,mi)    (((ma) << MINORBITS) | (mi))
#define B_FREE          0xffff          /* yuk */
#define B_FREE          0xffff          /* yuk */
 
 
extern char * kdevname(kdev_t); /* note: returns pointer to static data! */
extern char * kdevname(kdev_t); /* note: returns pointer to static data! */
 
 
/*
/*
As long as device numbers in the outside world have 16 bits only,
As long as device numbers in the outside world have 16 bits only,
we use these conversions.
we use these conversions.
*/
*/
 
 
static inline unsigned int kdev_t_to_nr(kdev_t dev) {
static inline unsigned int kdev_t_to_nr(kdev_t dev) {
        return (MAJOR(dev)<<8) | MINOR(dev);
        return (MAJOR(dev)<<8) | MINOR(dev);
}
}
 
 
static inline kdev_t to_kdev_t(int dev)
static inline kdev_t to_kdev_t(int dev)
{
{
        int major, minor;
        int major, minor;
#if 0
#if 0
        major = (dev >> 16);
        major = (dev >> 16);
        if (!major) {
        if (!major) {
                major = (dev >> 8);
                major = (dev >> 8);
                minor = (dev & 0xff);
                minor = (dev & 0xff);
        } else
        } else
                minor = (dev & 0xffff);
                minor = (dev & 0xffff);
#else
#else
        major = (dev >> 8);
        major = (dev >> 8);
        minor = (dev & 0xff);
        minor = (dev & 0xff);
#endif
#endif
        return MKDEV(major, minor);
        return MKDEV(major, minor);
}
}
 
 
#else /* __KERNEL__ */
#else /* __KERNEL__ */
 
 
/*
/*
Some programs want their definitions of MAJOR and MINOR and MKDEV
Some programs want their definitions of MAJOR and MINOR and MKDEV
from the kernel sources. These must be the externally visible ones.
from the kernel sources. These must be the externally visible ones.
*/
*/
#define MAJOR(dev)      ((dev)>>8)
#define MAJOR(dev)      ((dev)>>8)
#define MINOR(dev)      ((dev) & 0xff)
#define MINOR(dev)      ((dev) & 0xff)
#define MKDEV(ma,mi)    ((ma)<<8 | (mi))
#define MKDEV(ma,mi)    ((ma)<<8 | (mi))
#endif /* __KERNEL__ */
#endif /* __KERNEL__ */
#endif
#endif
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.