dev_hdr.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Mach Operating System
  3. * Copyright (c) 1991,1990,1989 Carnegie Mellon University
  4. * All Rights Reserved.
  5. *
  6. * Permission to use, copy, modify and distribute this software and its
  7. * documentation is hereby granted, provided that both the copyright
  8. * notice and this permission notice appear in all copies of the
  9. * software, derivative works or modified versions, and any portions
  10. * thereof, and that both notices appear in supporting documentation.
  11. *
  12. * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  13. * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  14. * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  15. *
  16. * Carnegie Mellon requests users of this software to return to
  17. *
  18. * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
  19. * School of Computer Science
  20. * Carnegie Mellon University
  21. * Pittsburgh PA 15213-3890
  22. *
  23. * any improvements or extensions that they make and grant Carnegie Mellon
  24. * the rights to redistribute these changes.
  25. */
  26. /*
  27. * Author: David B. Golub, Carnegie Mellon University
  28. * Date: 3/89
  29. */
  30. /*
  31. * Mach device emulation definitions (i386at version).
  32. *
  33. * Copyright (c) 1996 The University of Utah and
  34. * the Computer Systems Laboratory at the University of Utah (CSL).
  35. * All rights reserved.
  36. *
  37. * Permission to use, copy, modify and distribute this software is hereby
  38. * granted provided that (1) source code retains these copyright, permission,
  39. * and disclaimer notices, and (2) redistributions including binaries
  40. * reproduce the notices in supporting documentation, and (3) all advertising
  41. * materials mentioning features or use of this software display the following
  42. * acknowledgement: ``This product includes software developed by the
  43. * Computer Systems Laboratory at the University of Utah.''
  44. *
  45. * THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
  46. * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF
  47. * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  48. *
  49. * CSL requests users of this software to return to csl-dist@cs.utah.edu any
  50. * improvements that they make and grant CSL redistribution rights.
  51. *
  52. * Author: Shantanu Goel, University of Utah CSL
  53. */
  54. #ifndef _DEVICE_DEV_HDR_H_
  55. #define _DEVICE_DEV_HDR_H_
  56. #include <ipc/ipc_types.h>
  57. #include <mach/port.h>
  58. #include <kern/lock.h>
  59. #include <kern/queue.h>
  60. #include <device/conf.h>
  61. /* This structure is associated with each open device port.
  62. The port representing the device points to this structure. */
  63. struct device
  64. {
  65. struct device_emulation_ops *emul_ops;
  66. void *emul_data;
  67. };
  68. typedef struct device *device_t;
  69. #define DEVICE_NULL ((device_t) 0)
  70. /*
  71. * Generic device header. May be allocated with the device,
  72. * or built when the device is opened.
  73. */
  74. struct mach_device {
  75. decl_simple_lock_data(,ref_lock)/* lock for reference count */
  76. int ref_count; /* reference count */
  77. decl_simple_lock_data(, lock) /* lock for rest of state */
  78. short state; /* state: */
  79. #define DEV_STATE_INIT 0 /* not open */
  80. #define DEV_STATE_OPENING 1 /* being opened */
  81. #define DEV_STATE_OPEN 2 /* open */
  82. #define DEV_STATE_CLOSING 3 /* being closed */
  83. short flag; /* random flags: */
  84. #define D_EXCL_OPEN 0x0001 /* open only once */
  85. short open_count; /* number of times open */
  86. short io_in_progress; /* number of IOs in progress */
  87. boolean_t io_wait; /* someone waiting for IO to finish */
  88. struct ipc_port *port; /* open port */
  89. queue_chain_t number_chain; /* chain for lookup by number */
  90. int dev_number; /* device number */
  91. int bsize; /* replacement for DEV_BSIZE */
  92. struct dev_ops *dev_ops; /* and operations vector */
  93. struct device dev; /* the real device structure */
  94. };
  95. typedef struct mach_device *mach_device_t;
  96. #define MACH_DEVICE_NULL ((mach_device_t)0)
  97. /*
  98. * To find and remove device entries
  99. */
  100. mach_device_t device_lookup(char *); /* by name */
  101. void mach_device_reference(mach_device_t);
  102. void mach_device_deallocate(mach_device_t);
  103. /*
  104. * To find and remove port-to-device mappings
  105. */
  106. device_t dev_port_lookup(ipc_port_t);
  107. void dev_port_enter(mach_device_t);
  108. void dev_port_remove(mach_device_t);
  109. /*
  110. * To call a routine on each device
  111. */
  112. boolean_t dev_map(boolean_t (*)(), mach_port_t);
  113. /*
  114. * To lock and unlock state and open-count
  115. */
  116. #define device_lock(device) simple_lock(&(device)->lock)
  117. #define device_unlock(device) simple_unlock(&(device)->lock)
  118. /*
  119. * device name lookup
  120. */
  121. extern boolean_t dev_name_lookup(
  122. char * name,
  123. dev_ops_t *ops, /* out */
  124. int *unit); /* out */
  125. /*
  126. * Change an entry in the indirection list.
  127. */
  128. extern void dev_set_indirection(
  129. const char *name,
  130. dev_ops_t ops,
  131. int unit);
  132. #endif /* _DEVICE_DEV_HDR_H_ */