home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Workbench / dosdrivers / A!FF4313.LHA / FFS43_13 / NewStyleCommands < prev    next >
Encoding:
Text File  |  1996-07-15  |  14.5 KB  |  388 lines

  1.  
  2.     $Id: NewStyleCommands 1.4 1996/07/15 18:41:23 heinz Exp $
  3.  
  4. What is this about?
  5. ===================
  6.  
  7. Up to and including OS 3.1 (V40), custom device commands usually
  8. started at CMD_NONSTD. Each developer added commands for custom
  9. device features freely. This lead to messy and incompatible
  10. devices and strange compatibility tricks to identify device
  11. capabilities.
  12.  
  13. As of January 1st, 1996, Amiga Technologies reserves two ranges in
  14. the set of command values for future enhancements. Only commands as
  15. specified by Amiga Technologies may be used here. It is illegal for
  16. a device developer to randomly "add" custom commands or
  17. command features in the reserved are!
  18.  
  19. There are 65536 command values possible with io_Command:
  20.  
  21.     $0000 - $3fff       old style and 3rd party commands
  22.     $4000 - $7fff       RESERVED AREA!
  23.     $8000 - $bfff       old style and 3rd party commands
  24.     $c000 - $ffff       RESERVED AREA!
  25.  
  26. To say it again: Commands in the reserved areas may only be
  27. assigned and specified by Amiga Technologies. Any "custom"
  28. implementation of these commands or other commands in these
  29. reserved areas is illegal and violates programming standards!
  30.  
  31. A device driver is REQUIRED to return IOERR_NOCMD on any command it
  32. does not understand. This requirement is very old. It has been
  33. documented publically in 1991 already.
  34.  
  35. Commands in the reserved ranges are called "new style". A device
  36. that supports new style commands correctly as described in this
  37. document is called a "new style device".
  38.  
  39.  
  40. What will new style commands do for you?
  41. ========================================
  42.  
  43. With old style devices it is impossible to find out about the type
  44. of device you are accessing. You don't know if it is serial.device
  45. like or a trackdisk style device. New style commands will let you
  46. query the device for its capabilities. As capabilities are added
  47. to a device, device users can use more features transparently
  48. without compatibility hacks.
  49.  
  50. There are two types of new style commands. "General" commands are
  51. the same for all new style devices. Depending on the device type
  52. there are device specific commands, too.
  53.  
  54. General commands will be defined in the range $4000-$7fff, device
  55. specific commands are using the range $c000-$ffff. It is illegal to
  56. use a device specific command before using the general commands to
  57. confirm the device's capabilities.
  58.  
  59. With a new style device, you can be sure that no 3rd party command
  60. will interact with the standard meaning of all the device's
  61. commands as documented for V40 of the OS.
  62.  
  63.  
  64. Basic requirements
  65. ==================
  66.  
  67. Let's make a quick list about the most basic requirements for any new
  68. style device. Keep it in mind when reading on.
  69.  
  70.     - IOERR_NOCMD support
  71.     - no redefinition of standard V40 or reserved commands
  72.     - no 3rd party commands in reserved areas
  73.     - NSCMD_DEVICEQUERY is supported
  74.     - lib_IdString must contain the name, version, and creation
  75.       date of the device and any other readable information to make
  76.       unique identification of a device for 3rd party
  77.       command use possible.
  78.     - Check mn_Length of the request on OpenDevice
  79.  
  80. Some devices may have additional requirements. These will be listed
  81. below.
  82.  
  83.  
  84. General commands
  85. ================
  86.  
  87. At the moment there is just a single new style general command:
  88.  
  89. #define NSCMD_DEVICEQUERY   0x4000
  90.  
  91. It is required for all new style devices.
  92.  
  93. You set up io_Data and io_Length pointing to a struct
  94. NSDeviceQueryResult below. You must clear SizeAvailable and set up
  95. DevQueryFormat before sending the command to the device. A new
  96. style device will set up the data in the buffer appropriately. If
  97. the command executed successfully the returned io_Actual value must
  98. be greater than zero and equal to the SizeAvailable value that has
  99. been set by the device. The device may only be considered a new
  100. style device if these conditions are met. And only in this case the
  101. results of the query may be considered valid.
  102.  
  103. struct NSDeviceQueryResult
  104. {
  105.     /*
  106.     ** Standard information
  107.     */
  108.     ULONG   DevQueryFormat;         /* this is type 0               */
  109.     ULONG   SizeAvailable;          /* bytes available              */
  110.  
  111.     /*
  112.     ** Common information (READ ONLY!)
  113.     */
  114.     UWORD   DeviceType;             /* what the device does         */
  115.     UWORD   DeviceSubType;          /* depends on the main type     */
  116.     UWORD   *SupportedCommands;     /* 0 terminated list of cmd's   */
  117.  
  118.     /* May be extended in the future! Check SizeAvailable! */
  119. };
  120.  
  121. The device will fill in the struct NSDeviceQueryResult with read
  122. only data for the caller. All data must remain constant and valid
  123. as long as the device is open. After CloseDevice(), all bets are
  124. off.
  125.  
  126.     SizeAvailable
  127.  
  128.         Tells you how much of the structure contains valid data. It
  129.         is measured in bytes. Do not try to use fields in the
  130.         strutcure that are not fully included in the SizeAvailable
  131.         range. SizeAvailable must include SupportedCommands for any
  132.         successful query. So the minimum valid value is 16.
  133.  
  134.     DeviceType
  135.  
  136.         This tells you about the type of device you are accessing.
  137.         The type names often match existing devices in AmigaOS. If
  138.         a device returns such a type, the device must be able to
  139.         at least handle all the documented features for V40 of the
  140.         operating system that the respective original device has.
  141.  
  142.         If an old style or new style command can not be supported
  143.         in a compatible manner, the device is required to return
  144.         IOERR_NOCMD for safety reasons. Modification of the
  145.         specification is not allowed. Add a 3rd party command if
  146.         needed.
  147.  
  148.         It is illegal to "reuse" command numbers of documented
  149.         standard commands that cannot be supported for other
  150.         purposes. E.g. a device driver that does not support
  151.         TD_GETGEOMETRY and uses it for something else can never be
  152.         a new style device and may not support new style commands.
  153.  
  154.         It is also illegal to use the results of an
  155.         NSCMD_DEVICEQUERY without testing DeviceType first.
  156.  
  157. #define NSDEVTYPE_UNKNOWN       0   /* No suitable category, anything */
  158. #define NSDEVTYPE_GAMEPORT      1   /* like gameport.device */
  159. #define NSDEVTYPE_TIMER         2   /* like timer.device */
  160. #define NSDEVTYPE_KEYBOARD      3   /* like keyboard.device */
  161. #define NSDEVTYPE_INPUT         4   /* like input.device */
  162. #define NSDEVTYPE_TRACKDISK     5   /* like trackdisk.device */
  163. #define NSDEVTYPE_CONSOLE       6   /* like console.device */
  164. #define NSDEVTYPE_SANA2         7   /* A >=SANA2R2 networking device */
  165. #define NSDEVTYPE_AUDIOARD      8   /* like audio.device */
  166. #define NSDEVTYPE_CLIPBOARD     9   /* like clipboard.device */
  167. #define NSDEVTYPE_PRINTER       10  /* like printer.device */
  168. #define NSDEVTYPE_SERIAL        11  /* like serial.device */
  169. #define NSDEVTYPE_PARALLEL      12  /* like parallel.device */
  170.  
  171.         More types will be defined by Amiga Technologies as
  172.         necessary and requested. Each device type represents a
  173.         certain set of minimum capabilities that the device must
  174.         support. If the type does not match a device that does
  175.         exist in OS V40, the exact requirements are defined below.
  176.  
  177.     DeviceSubType
  178.  
  179.         There might be special incarnations of a device with
  180.         special capabilities beyond the standard set. At the moment
  181.         none are defined and a device is required to return 0 here.
  182.         As extensions that are marked by this field have to be
  183.         upwards compatible, this field need not be tested by users
  184.         who don't need any special capabilities beyond the standard
  185.         set. Otherwise it must be tested first.
  186.  
  187.     SupportedCommands
  188.  
  189.         This points to a 0 terminated list of io_Command values
  190.         that are supported by the device. This list must contain
  191.         all legal command values, old style, new style, and special
  192.         commands that are understood by the device and do not
  193.         cause an IOERR_NOCMD right away.
  194.  
  195.  
  196. You might notice the similarity to the SANA2-R2 (S2R2) S2_DEVICEQUERY
  197. command. It is intentional.
  198.  
  199. If you are developing software that needs to use 3rd party
  200. commands, you must try an *exact* 3rd party device identification
  201. via the lib_IdString in the device base and reject all devices that
  202. you don't know for a new style device.
  203.  
  204.  
  205. New Style Check in C
  206. ====================
  207.  
  208. A code fragment that could help you set up a new device query
  209. follows.
  210.  
  211.     struct IOStdReq *io;
  212.     struct NSDeviceQueryResult nsdqr;
  213.     LONG error;
  214.     BOOL newstyle = FALSE;
  215.     BOOL does64bit = FALSE;
  216.     UWORD *cmdcheck;
  217.     struct MsgPort *replyport;
  218.  
  219.     ...
  220.     /* See important caveat below! */
  221.     io = CreateIORequest(replyport, sizeof(struct IOStdReq) + 128);
  222.  
  223.     ...
  224.     nsdqr.SizeAvailable  = 0;
  225.     nsdqr.DevQueryFormat = 0;
  226.  
  227.     io->io_Command = NSCMD_DEVICEQUERY;
  228.     io->io_Length  = sizeof(nsdqr);
  229.     io->io_Data    = (APTR)&nsdqr;
  230.     error = DoIO((struct IORequest *)io);
  231.     if((!error) &&
  232.        (io->io_Actual >= 16) &&
  233.        (nsdqr.SizeAvailable == io->io_Actual) &&
  234.        (nsdqr.DeviceType == NSDEVTYPE_TRACKDISK))
  235.     {
  236.         /* Ok, this must be a new style trackdisk device */
  237.         newstyle = TRUE;
  238.  
  239.         /* Is it safe to use 64 bits with this driver? We can reject
  240.          * bad mounts pretty easily via this check!
  241.          */
  242.         for(cmdcheck = nsdqr.SupportedCommands;
  243.             *cmdcheck;
  244.             cmdcheck++)
  245.         {
  246.             if(*cmdcheck == NSCMD_TD_READ64)
  247.             {
  248.                 /* This trackdisk style device supports the complete
  249.                  * 64 bit command set without returning IOERR_NOCMD!
  250.                  */
  251.                 does64bit = TRUE;
  252.             } /* if */
  253.         } /* for */
  254.     } /* if */
  255.  
  256. *** CAVEAT ***: This code fragment uses a pointer to an IOStdReq to
  257. do the checks. Unfortunately, using a request of this size may
  258. result in severe problems with certain devices like SANA-II
  259. devices, which need a larger request structure. A current device
  260. should check in its OpenDevice code if the passed in request is
  261. large enough to work with via its mn_Length field and fail to open
  262. if it isn't. Unfortunately most devices don't do that check. Two
  263. basic assumptions are possible:
  264.  
  265.     1. The trusting assumption
  266.  
  267.         You simply use the type and size of request structure
  268.         appropriate for the type of device you intend to use and
  269.         assume that the user did not give you the wrong type
  270.         of device. This may fail and result in a system crash.
  271.  
  272.     2. The safer assumption
  273.  
  274.         You use the type of request for the device type your are
  275.         expecting (or an IOStdReq for a general check) with an
  276.         extra 128 zeroed bytes when opening and checking a device.
  277.         This will be very safe as current devices are required to
  278.         check the minimum request length before opening
  279.         successfully. So any wrong type of device will not cause
  280.         problems here unless it both
  281.  
  282.             - uses a really strange long request that is
  283.               referenced on OpenDevice() time
  284.  
  285.         and
  286.  
  287.             - does not implement the required mn_Length check
  288.  
  289.         You only need that one larger request for the check on
  290.         opening the device. Afterwards you know what you are
  291.         working with and can use reasonably sized requests.
  292.  
  293. Obviously we cannot approve of the trusting assumption, so we
  294. require you to implement the safer assumption. The basic idea
  295. behind this is that you should always strive to make device access
  296. as safe as possible. Some little things like validating the
  297. request structure on OpenDevice will increase stability of the
  298. device system a lot. Play it safe. The user might have some messed
  299. up code accessing the device!
  300.  
  301.  
  302. Device specific requirements
  303. ============================
  304.  
  305. Depending on the type returned by NSCMD_DEVICEQUERY, a device may
  306. support device specific commands in the $c000-$ffff range.
  307.  
  308. It is valid and strongly suggested behaviour for a device to reject
  309. all new style commands except NSCMD_DEVICEQUERY with IOERR_NOCMD
  310. unless the caller executed a valid and successful NSCMD_DEVICEQUERY
  311. at least once before.
  312.  
  313. There is also a minimum list of requirements for some types of
  314. devices.
  315.  
  316. If a device type is not listed below, no device specific commands
  317. are defined for it at this time. The device might still support
  318. special custom 3rd party commands outside the reserved range,
  319. though. If a device type is listed below, the device driver must
  320. conform to the mentioned specifications. A new style device
  321. specific command may possibly match an old style extended command
  322. exactly to avoid future identification troubles or code
  323. misunderstanding.
  324.  
  325.  
  326. Device specific commands and behaviour
  327. --------------------------------------
  328.  
  329. NSDEVTYPE_TRACKDISK
  330.  
  331.     May support all V40 trackdisk.device commands and
  332.     possibly HD_SCSICMD as scsidisk.device is obviousy a trackdisk
  333.     like driver. If it doesn't, IOERR_NOCMD must be returned for
  334.     the respective command. 3rd party commands may be added in
  335.     slots that don't conflict with the V40 command set or the
  336.     reserved areas.
  337.  
  338.     A new style trackdisk like device *must* also return this
  339.     new identifier for TD_GETDRIVETYPE. You should use
  340.     TD_GETGEOMETRY on a new style driver to obtain geometry hints
  341.     if needed.
  342.  
  343.         #define DRIVE_NEWSTYLE  (0x4E535459L)   /* 'NSTY' */
  344.  
  345.  
  346.     At the moment, only four new style commands in the device
  347.     specific range may be implemented.
  348.  
  349.     #define NSCMD_TD_READ64     0xc000
  350.     #define NSCMD_TD_WRITE64    0xc001
  351.     #define NSCMD_TD_SEEK64     0xc002
  352.     #define NSCMD_TD_FORMAT64   0xc003
  353.  
  354.         These commands behave almost like the trackdisk commands
  355.         CMD_READ, CMD_WRITE, TD_FORMAT, respectively, but support 64
  356.         bit handling for large storage devices. The upper 32 bits,
  357.         bit 32 to 63, need to be put into io_Actual before the
  358.         commands are executed. io_Actual can be named io_HighOffset
  359.         in that case.
  360.  
  361.         If you choose to implement the 64 bit commands, you must
  362.         implement all of them, even if some of them would possibly
  363.         return dummy results. A partial implementation with some 64
  364.         bit commands returning IOERR_NOCMD is not acceptable.
  365.  
  366.         A detailed description of the 64 bit commands can be found
  367.         in the document "trackdisk64". Implementors are required to
  368.         read this document.
  369.  
  370.  
  371. Recommended use
  372. ===============
  373.  
  374. Anyone who wants to take advantage of the new style device
  375. interface should do this:
  376.  
  377.     - OpenDevice() as usual
  378.     - Try a NSCMD_DEVICEQUERY
  379.     - If successful according to the rules mentioned above,
  380.       use the commands as listed in "SupportedCommands".
  381.     - Otherwise it must be an old style device. Hope and pray that
  382.       you got what you wanted.
  383.  
  384. *** EOT ***
  385.  
  386. Heinz Wrobel
  387. <heinz@amiga.de>
  388.