1 /* 2 * Copyright 2002, Thomas Kurschel. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef __SCSI_PERIPH_INT_H__ 6 #define __SCSI_PERIPH_INT_H__ 7 8 9 #include <scsi_periph.h> 10 #include <block_io.h> 11 #include <device_manager.h> 12 13 #include <stddef.h> 14 15 #include "wrapper.h" 16 17 18 typedef struct scsi_periph_device_info { 19 struct scsi_periph_handle_info *handles; 20 21 scsi_device scsi_device; 22 scsi_device_interface *scsi; 23 periph_device_cookie periph_device; 24 device_node_handle node; 25 26 bool removal_requested; 27 28 bool removable; // true, if device is removable 29 30 int32 rw10_enabled; // 10 byte r/w commands supported; access must be atomic 31 int32 next_tag_action; // queuing flag for next r/w command; access must be atomic 32 33 benaphore mutex; 34 int std_timeout; 35 36 scsi_periph_callbacks *callbacks; 37 } scsi_periph_device_info; 38 39 typedef struct scsi_periph_handle_info { 40 scsi_periph_device_info *device; 41 struct scsi_periph_handle_info *next, *prev; 42 43 int pending_error; // error to be reported on all accesses 44 // (used to block access after medium change until 45 // B_GET_MEDIA_STATUS is called) 46 periph_handle_cookie periph_handle; 47 } scsi_periph_handle_info; 48 49 extern device_manager_info *pnp; 50 51 52 // removable.c 53 54 void periph_media_changed(scsi_periph_device_info *device, scsi_ccb *ccb); 55 void periph_media_changed_public(scsi_periph_device_info *device); 56 status_t periph_get_media_status(scsi_periph_handle_info *handle); 57 err_res periph_send_start_stop(scsi_periph_device_info *device, scsi_ccb *request, 58 bool start, bool with_LoEj); 59 60 61 // error_handling.c 62 63 err_res periph_check_error(scsi_periph_device_info *device, scsi_ccb *request); 64 65 66 // handle.c 67 68 status_t periph_handle_open(scsi_periph_device_info *device, periph_handle_cookie periph_handle, 69 scsi_periph_handle_info **res_handle); 70 status_t periph_handle_close(scsi_periph_handle_info *handle); 71 status_t periph_handle_free(scsi_periph_handle_info *handle); 72 73 74 // block.c 75 76 status_t periph_check_capacity(scsi_periph_device_info *device, scsi_ccb *ccb); 77 78 79 // device.c 80 81 status_t periph_register_device(periph_device_cookie periph_device, 82 scsi_periph_callbacks *callbacks, scsi_device scsi_device, scsi_device_interface *scsi, 83 device_node_handle node, bool removable, scsi_periph_device *driver); 84 status_t periph_unregister_device(scsi_periph_device_info *driver); 85 char *periph_compose_device_name(device_node_handle device_node, const char *prefix); 86 87 88 // io.c 89 90 status_t periph_read(scsi_periph_handle_info *handle, const phys_vecs *vecs, 91 off_t pos, size_t num_blocks, uint32 block_size, size_t *bytes_transferred, 92 int preferred_ccb_size); 93 status_t periph_write(scsi_periph_handle_info *handle, const phys_vecs *vecs, 94 off_t pos, size_t num_blocks, uint32 block_size, size_t *bytes_transferred, 95 int preferred_ccb_size); 96 status_t periph_ioctl(scsi_periph_handle_info *handle, int op, 97 void *buf, size_t len); 98 void periph_sync_queue_daemon(void *arg, int iteration); 99 100 101 // scsi_periph.c 102 103 status_t periph_safe_exec(scsi_periph_device_info *device, scsi_ccb *request); 104 status_t periph_simple_exec(scsi_periph_device_info *device, void *cdb, 105 uchar cdb_len, void *data, size_t data_len, int ccb_flags); 106 107 108 // device_icons.c 109 110 status_t periph_get_icon(icon_type type, device_icon *data); 111 112 // sync.c 113 114 err_res periph_synchronize_cache(scsi_periph_device_info *device, 115 scsi_ccb *request); 116 117 #endif /* __SCSI_PERIPH_INT_H__ */ 118