- added runtime configuration parameters for USB cdrom drive

- scsi_device: changed some variable types
- usb_hub: removed unused method
This commit is contained in:
Volker Ruppert 2009-04-06 15:36:55 +00:00
parent 0a37bcfbdc
commit 11fa3b2c4a
5 changed files with 122 additions and 11 deletions

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// $Id: scsi_device.cc,v 1.16 2009-04-05 16:28:35 vruppert Exp $ // $Id: scsi_device.cc,v 1.17 2009-04-06 15:36:53 vruppert Exp $
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// Copyright (C) 2007 Volker Ruppert // Copyright (C) 2007 Volker Ruppert
@ -213,7 +213,7 @@ void scsi_device_t::scsi_read_data(Bit32u tag)
scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_HARDWARE_ERROR); scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_HARDWARE_ERROR);
return; return;
} }
if (r->sector_count == -1) { if (r->sector_count == (Bit32u)-1) {
BX_DEBUG(("read buf_len=%d", r->buf_len)); BX_DEBUG(("read buf_len=%d", r->buf_len));
r->sector_count = 0; r->sector_count = 0;
completion(dev, SCSI_REASON_DATA, r->tag, r->buf_len); completion(dev, SCSI_REASON_DATA, r->tag, r->buf_len);

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// $Id: scsi_device.h,v 1.11 2009-04-05 16:28:35 vruppert Exp $ // $Id: scsi_device.h,v 1.12 2009-04-06 15:36:54 vruppert Exp $
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// Copyright (C) 2007 Volker Ruppert // Copyright (C) 2007 Volker Ruppert
@ -52,8 +52,8 @@ enum scsi_reason {
typedef struct SCSIRequest { typedef struct SCSIRequest {
scsi_device_t *dev; scsi_device_t *dev;
Bit32u tag; Bit32u tag;
int sector; Bit64u sector;
int sector_count; Bit32u sector_count;
int buf_len; int buf_len;
Bit8u dma_buf[SCSI_DMA_BUF_SIZE]; Bit8u dma_buf[SCSI_DMA_BUF_SIZE];
Bit32u status; Bit32u status;
@ -80,6 +80,8 @@ public:
Bit8u* scsi_get_buf(Bit32u tag); Bit8u* scsi_get_buf(Bit32u tag);
const char *get_serial_number() {return drive_serial_str;} const char *get_serial_number() {return drive_serial_str;}
void set_inserted(bx_bool value) {inserted = value;} void set_inserted(bx_bool value) {inserted = value;}
bx_bool get_inserted() {return inserted;}
protected: protected:
SCSIRequest* scsi_new_request(Bit32u tag); SCSIRequest* scsi_new_request(Bit32u tag);
void scsi_remove_request(SCSIRequest *r); void scsi_remove_request(SCSIRequest *r);

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// $Id: usb_hub.h,v 1.3 2009-03-15 12:54:59 vruppert Exp $ // $Id: usb_hub.h,v 1.4 2009-04-06 15:36:54 vruppert Exp $
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// Copyright (C) 2009 Volker Ruppert // Copyright (C) 2009 Volker Ruppert
@ -38,7 +38,6 @@ public:
virtual int handle_data(USBPacket *p); virtual int handle_data(USBPacket *p);
virtual void register_state_specific(bx_list_c *parent); virtual void register_state_specific(bx_list_c *parent);
virtual void after_restore_state(); virtual void after_restore_state();
const char *get_name() {return hub.config->get_name();}
private: private:
struct { struct {

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// $Id: usb_msd.cc,v 1.21 2009-04-03 16:42:56 vruppert Exp $ // $Id: usb_msd.cc,v 1.22 2009-04-06 15:36:54 vruppert Exp $
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// Copyright (C) 2009 Volker Ruppert // Copyright (C) 2009 Volker Ruppert
@ -131,17 +131,45 @@ static const Bit8u bx_msd_config_descriptor[] = {
0x00 /* u8 ep_bInterval; */ 0x00 /* u8 ep_bInterval; */
}; };
static int cdrom_count = 0;
usb_msd_device_c::usb_msd_device_c(usbdev_type type, const char *filename) usb_msd_device_c::usb_msd_device_c(usbdev_type type, const char *filename)
{ {
char pname[10];
char label[32];
bx_param_string_c *path;
bx_param_bool_c *status;
d.type = type; d.type = type;
d.speed = USB_SPEED_FULL; d.speed = USB_SPEED_FULL;
memset((void*)&s, 0, sizeof(s));
s.fname = filename;
if (d.type == USB_DEV_TYPE_DISK) { if (d.type == USB_DEV_TYPE_DISK) {
strcpy(d.devname, "BOCHS USB HARDDRIVE"); strcpy(d.devname, "BOCHS USB HARDDRIVE");
} else if (d.type == USB_DEV_TYPE_CDROM) { } else if (d.type == USB_DEV_TYPE_CDROM) {
strcpy(d.devname, "BOCHS USB CDROM"); strcpy(d.devname, "BOCHS USB CDROM");
// config options
bx_list_c *usb_rt = (bx_list_c*)SIM->get_param(BXPN_MENU_RUNTIME_USB);
sprintf(pname, "cdrom%d", ++cdrom_count);
sprintf(label, "USB CD-ROM #%d Configuration", cdrom_count);
s.config = new bx_list_c(usb_rt, pname, label, 2);
s.config->set_options(bx_list_c::SERIES_ASK | bx_list_c::USE_BOX_TITLE);
s.config->set_runtime_param(1);
s.config->set_device_param(this);
path = new bx_param_string_c(s.config, "path", "Path", "", "", BX_PATHNAME_LEN);
path->set(s.fname);
path->set_handler(cd_param_string_handler);
path->set_runtime_param(1);
status = new bx_param_bool_c(s.config, "status", "Inserted", "", 1);
status->set_handler(cd_param_handler);
status->set_runtime_param(1);
// TODO: status
#if BX_WITH_WX
bx_list_c *usb = (bx_list_c*)SIM->get_param("ports.usb");
usb->add(s.config);
#endif
} }
memset((void*)&s, 0, sizeof(s));
s.fname = filename;
put("USBMS"); put("USBMS");
} }
@ -154,6 +182,12 @@ usb_msd_device_c::~usb_msd_device_c(void)
delete s.hdimage; delete s.hdimage;
} else if (s.cdrom != NULL) { } else if (s.cdrom != NULL) {
delete s.cdrom; delete s.cdrom;
#if BX_WITH_WX
bx_list_c *usb = (bx_list_c*)SIM->get_param("ports.usb");
usb->remove(s.config->get_name());
#endif
bx_list_c *usb_rt = (bx_list_c*)SIM->get_param(BXPN_MENU_RUNTIME_USB);
usb_rt->remove(s.config->get_name());
} }
} }
@ -568,4 +602,73 @@ void usb_msd_device_c::cancel_packet(USBPacket *p)
s.scsi_len = 0; s.scsi_len = 0;
} }
void usb_msd_device_c::set_inserted(bx_bool value)
{
const char *path;
if (value) {
path = SIM->get_param_string("path", s.config)->getptr();
if (!s.cdrom->insert_cdrom(path)) {
SIM->get_param_bool("status", s.config)->set(0);
return;
}
} else {
s.cdrom->eject_cdrom();
}
s.scsi_dev->set_inserted(value);
}
bx_bool usb_msd_device_c::get_inserted()
{
return s.scsi_dev->get_inserted();
}
#undef LOG_THIS
#define LOG_THIS cdrom->
// USB hub runtime parameter handlers
const char *usb_msd_device_c::cd_param_string_handler(bx_param_string_c *param, int set,
const char *oldval, const char *val, int maxlen)
{
usb_msd_device_c *cdrom;
if (set) {
cdrom = (usb_msd_device_c*) param->get_parent()->get_device_param();
if (cdrom != NULL) {
bx_bool empty = ((strlen(val) == 0) || (!strcmp(val, "none")));
if (!empty) {
if (cdrom->get_inserted()) {
BX_ERROR(("direct path change not supported (setting to 'none')"));
param->set("none");
}
} else {
SIM->get_param_bool("status", param->get_parent())->set(0);
}
} else {
BX_PANIC(("cd_param_string_handler: cdrom not found"));
}
}
return val;
}
Bit64s usb_msd_device_c::cd_param_handler(bx_param_c *param, int set, Bit64s val)
{
usb_msd_device_c *cdrom;
const char *path;
if (set) {
cdrom = (usb_msd_device_c*) param->get_parent()->get_device_param();
if (cdrom != NULL) {
path = SIM->get_param_string("path", param->get_parent())->getptr();
val &= ((strlen(path) > 0) && (strcmp(path, "none")));
if (val != cdrom->get_inserted()) {
cdrom->set_inserted(val);
}
} else {
BX_PANIC(("cd_param_string_handler: cdrom not found"));
}
}
return val;
}
#endif // BX_SUPPORT_PCI && BX_SUPPORT_PCIUSB #endif // BX_SUPPORT_PCI && BX_SUPPORT_PCIUSB

View File

@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// $Id: usb_msd.h,v 1.12 2009-03-09 12:18:40 vruppert Exp $ // $Id: usb_msd.h,v 1.13 2009-04-06 15:36:55 vruppert Exp $
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// //
// Copyright (C) 2009 Volker Ruppert // Copyright (C) 2009 Volker Ruppert
@ -40,6 +40,8 @@ public:
virtual int handle_data(USBPacket *p); virtual int handle_data(USBPacket *p);
virtual void register_state_specific(bx_list_c *parent); virtual void register_state_specific(bx_list_c *parent);
virtual void cancel_packet(USBPacket *p); virtual void cancel_packet(USBPacket *p);
void set_inserted(bx_bool value);
bx_bool get_inserted();
protected: protected:
void copy_data(); void copy_data();
@ -64,7 +66,12 @@ private:
USBPacket *packet; USBPacket *packet;
bx_list_c *sr_list; bx_list_c *sr_list;
const char *fname; const char *fname;
bx_list_c *config;
} s; } s;
static const char *cd_param_string_handler(bx_param_string_c *param, int set,
const char *oldval, const char *val, int maxlen);
static Bit64s cd_param_handler(bx_param_c *param, int set, Bit64s val);
}; };
#endif #endif