cuda: misc fixes and cleanups
v2 cover cuda: misc fixes and cleanups
Hi,
This patchset cleans up a little bit the Apple CUDA emulation:
- correctly reject commands with wrong parameters
- support changing the frequency of auto-polling
- support changing device list probed in auto-poll
- add logs when using FILE_SERVER_FLAG/SET_POWER_MESSAGE
- remove unused commands (GET/SET_6805_ADDR)
- remove unimplemented GET_SET_IIC/COMBINED_FORMAT_IIC
GET_SET_IIC/COMBINED_FORMAT_IIC commands should be added again once we implement the I2C bus provided by CUDA.
Hervé
Hervé Poussineau (13):
cuda: add a framework to handle commands
cuda: move unknown commands reject out of switch
cuda: port AUTOPOLL command to new framework
cuda: port SET_AUTO_RATE command to new framework
cuda: port SET_DEVICE_LIST command to new framework
cuda: port POWERDOWN command to new framework
cuda: port RESET_SYSTEM command to new framework
cuda: port FILE_SERVER_FLAG command to new framework
cuda: port SET_POWER_MESSAGES command to new framework
cuda: port GET_TIME command to new framework
cuda: port SET_TIME command to new framework
cuda: remove GET_6805_ADDR command
cuda: remove CUDA_GET_SET_IIC/CUDA_COMBINED_FORMAT_IIC commands
hw/input/adb.c | 18 ++-- hw/misc/macio/cuda.c | 279 ++++++++++++++++++++++++++++++++++++------------- hw/ppc/mac.h | 2 + include/hw/input/adb.h | 2 +- 4 files changed, 217 insertions(+), 84 deletions(-)
Signature · 1 line
2.1.4
PATCH v2 1/13 cuda: add a framework to handle commands
Next commits will port existing CUDA commands to this framework.
--- hw/misc/macio/cuda.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
hw/misc/macio/cuda.c +34 -0
@@ -535,13 +535,47 @@ static void cuda_adb_poll(void *opaque) (get_ticks_per_sec() / CUDA_ADB_POLL_FREQ)); } +/* description of commands */ +typedef struct CudaCommand { +uint8_t command; +const char *name; +bool (*handler)(CUDAState *s, +const uint8_t *in_args,int in_len, +uint8_t *out_args,int *out_len); +}CudaCommand ; + +static const CudaCommand handlers[] = { +}; +static void cuda_receive_packet (CUDAState *s,const uint8_t *data,int len) {uint8_t obuf[16 ] = {CUDA_PACKET ,0 , data[0 ] };int autopoll; +int i, out_len =0 ;uint32_t ti; +for (i =0 ; i <ARRAY_SIZE (handlers); i++) { +const CudaCommand *desc = &handlers[i]; +if (desc->command == data[0 ]) { +CUDA_DPRINTF ("handling command %s\n" , desc->name); + out_len =0 ; +if (desc->handler (s, data +1 , len -1 , obuf +3 , &out_len)) { +cuda_send_packet_to_host (s, obuf,3 + out_len); + }else { +qemu_log_mask (LOG_GUEST_ERROR , +"CUDA: %s: wrong parameters %d\n" , + desc->name, len); + obuf[0 ] =ERROR_PACKET ; + obuf[1 ] =0x5 ;/* bad parameters */ + obuf[2 ] =CUDA_PACKET ; + obuf[3 ] = data[0 ]; +cuda_send_packet_to_host (s, obuf,4 ); + } +return ; + } + } +switch (data[0 ]) {case CUDA_AUTOPOLL : autopoll = (data[1 ] !=0 );
Signature · 1 line
2.1.4
PATCH v2 2/13 cuda: move unknown commands reject out of switch
In reply to Hervé Poussineau--- hw/misc/macio/cuda.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-)
hw/misc/macio/cuda.c +16 -14
@@ -590,15 +590,15 @@ static void cuda_receive_packet(CUDAState *s, } }cuda_send_packet_to_host (s, obuf,3 ); -break ; +return ;case CUDA_GET_6805_ADDR :cuda_send_packet_to_host (s, obuf,3 ); -break ; +return ;case CUDA_SET_TIME : ti = (((uint32_t )data[1 ]) <<24 ) + (((uint32_t )data[2 ]) <<16 ) + (((uint32_t )data[3 ]) <<8 ) + data[4 ]; s->tick_offset = ti - (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) /get_ticks_per_sec ());cuda_send_packet_to_host (s, obuf,3 ); -break ; +return ;case CUDA_GET_TIME : ti = s->tick_offset + (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) /get_ticks_per_sec ()); obuf[3 ] = ti >>24 ;
@@ -606,28 +606,28 @@ static void cuda_receive_packet(CUDAState *s, obuf[5 ] = ti >>8 ; obuf[6 ] = ti;cuda_send_packet_to_host (s, obuf,7 ); -break ; +return ;case CUDA_FILE_SERVER_FLAG :case CUDA_SET_DEVICE_LIST :case CUDA_SET_AUTO_RATE :case CUDA_SET_POWER_MESSAGES :cuda_send_packet_to_host (s, obuf,3 ); -break ; +return ;case CUDA_POWERDOWN :cuda_send_packet_to_host (s, obuf,3 );qemu_system_shutdown_request (); -break ; +return ;case CUDA_RESET_SYSTEM :cuda_send_packet_to_host (s, obuf,3 );qemu_system_reset_request (); -break ; +return ;case CUDA_COMBINED_FORMAT_IIC : obuf[0 ] =ERROR_PACKET ; obuf[1 ] =0x5 ; obuf[2 ] =CUDA_PACKET ; obuf[3 ] = data[0 ];cuda_send_packet_to_host (s, obuf,4 ); -break ; +return ;case CUDA_GET_SET_IIC :if (len ==4 ) {cuda_send_packet_to_host (s, obuf,3 );
@@ -638,15 +638,17 @@ static void cuda_receive_packet(CUDAState *s, obuf[3 ] = data[0 ];cuda_send_packet_to_host (s, obuf,4 ); } -break ; +return ;default : - obuf[0 ] =ERROR_PACKET ; - obuf[1 ] =0x2 ; - obuf[2 ] =CUDA_PACKET ; - obuf[3 ] = data[0 ]; -cuda_send_packet_to_host (s, obuf,4 );break ; } + +qemu_log_mask (LOG_GUEST_ERROR ,"CUDA: unknown command 0x%02x\n" , data[0 ]); + obuf[0 ] =ERROR_PACKET ; + obuf[1 ] =0x2 ;/* unknown command */ + obuf[2 ] =CUDA_PACKET ; + obuf[3 ] = data[0 ]; +cuda_send_packet_to_host (s, obuf,4 ); } static void cuda_receive_packet_from_host(CUDAState *s,
Signature · 1 line
2.1.4
PATCH v2 3/13 cuda: port AUTOPOLL command to new framework
In reply to Hervé Poussineau--- hw/misc/macio/cuda.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-)
hw/misc/macio/cuda.c +25 -15
@@ -544,14 +544,38 @@ typedef struct CudaCommand { uint8_t *out_args, int *out_len); } CudaCommand; +static bool cuda_cmd_autopoll (CUDAState *s, +const uint8_t *in_data,int in_len, +uint8_t *out_data,int *out_len) +{ +int autopoll; + +if (in_len !=1 ) { +return false; + } + + autopoll = (in_data[0 ] !=0 ); +if (autopoll != s->autopoll) { + s->autopoll = autopoll; +if (autopoll) { +timer_mod (s->adb_poll_timer, +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + + (get_ticks_per_sec () /CUDA_ADB_POLL_FREQ )); + }else { +timer_del (s->adb_poll_timer); + } + } +return true; +} +static const CudaCommand handlers[] = { + {CUDA_AUTOPOLL ,"AUTOPOLL" , cuda_cmd_autopoll }, };static void cuda_receive_packet (CUDAState *s,const uint8_t *data,int len) {uint8_t obuf[16 ] = {CUDA_PACKET ,0 , data[0 ] }; -int autopoll;int i, out_len =0 ;uint32_t ti;
@@ -577,20 +601,6 @@ static void cuda_receive_packet(CUDAState *s, }switch (data[0 ]) { -case CUDA_AUTOPOLL : - autopoll = (data[1 ] !=0 ); -if (autopoll != s->autopoll) { - s->autopoll = autopoll; -if (autopoll) { -timer_mod (s->adb_poll_timer, -qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + - (get_ticks_per_sec () /CUDA_ADB_POLL_FREQ )); - }else { -timer_del (s->adb_poll_timer); - } - } -cuda_send_packet_to_host (s, obuf,3 ); -return ;case CUDA_GET_6805_ADDR :cuda_send_packet_to_host (s, obuf,3 );return ;
Signature · 1 line
2.1.4
PATCH v2 4/13 cuda: port SET_AUTO_RATE command to new framework
In reply to Hervé PoussineauAlso implement the command, by removing the hardcoded period of 20 ms/50 Hz and replacing it by the one requested by user.
Update VMState version to store this new parameter.
--- hw/misc/macio/cuda.c | 36 ++++++++++++++++++++++++++++++------ hw/ppc/mac.h | 1 + 2 files changed, 31 insertions(+), 6 deletions(-)
hw/misc/macio/cuda.c +30 -6
@@ -106,7 +106,6 @@#define CUDA_COMBINED_FORMAT_IIC 0x25#define CUDA_TIMER_FREQ (4700000 / 6) -#define CUDA_ADB_POLL_FREQ 50/* CUDA returns time_t's offset from Jan 1, 1904, not 1970 */ #define RTC_OFFSET 2082844800
@@ -532,7 +531,7 @@ static void cuda_adb_poll(void *opaque) }timer_mod (s->adb_poll_timer,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + - (get_ticks_per_sec () /CUDA_ADB_POLL_FREQ )); + (get_ticks_per_sec () / (1000 / s->autopoll_rate_ms))); }/* description of commands */
@@ -560,7 +559,7 @@ static bool cuda_cmd_autopoll(CUDAState *s,if (autopoll) {timer_mod (s->adb_poll_timer,qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + - (get_ticks_per_sec () /CUDA_ADB_POLL_FREQ )); + (get_ticks_per_sec () / (1000 / s->autopoll_rate_ms))); }else {timer_del (s->adb_poll_timer); }
@@ -568,8 +567,32 @@ static bool cuda_cmd_autopoll(CUDAState *s,return true; } +static bool cuda_cmd_set_autorate (CUDAState *s, +const uint8_t *in_data,int in_len, +uint8_t *out_data,int *out_len) +{ +if (in_len !=1 ) { +return false; + } + +/* we don't want a period of 0 ms */ +/* FIXME: check what real hardware does */ +if (in_data[0 ] ==0 ) { +return false; + } + + s->autopoll_rate_ms = in_data[0 ]; +if (s->autopoll) { +timer_mod (s->adb_poll_timer, +qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + + (get_ticks_per_sec () / (1000 / s->autopoll_rate_ms))); + } +return true; +} +static const CudaCommand handlers[] = { {CUDA_AUTOPOLL ,"AUTOPOLL" , cuda_cmd_autopoll }, + {CUDA_SET_AUTO_RATE ,"SET_AUTO_RATE" , cuda_cmd_set_autorate }, }; static void cuda_receive_packet(CUDAState *s,
@@ -619,7 +642,6 @@ static void cuda_receive_packet(CUDAState *s,return ;case CUDA_FILE_SERVER_FLAG :case CUDA_SET_DEVICE_LIST : -case CUDA_SET_AUTO_RATE :case CUDA_SET_POWER_MESSAGES :cuda_send_packet_to_host (s, obuf,3 );return ;
@@ -756,8 +778,8 @@ static const VMStateDescription vmstate_cuda_timer = {static const VMStateDescription vmstate_cuda = { .name ="cuda" , - .version_id =3 , - .minimum_version_id =3 , + .version_id =4 , + .minimum_version_id =4 , .fields = (VMStateField []) {VMSTATE_UINT8 (a, CUDAState),VMSTATE_UINT8 (b, CUDAState),
@@ -775,6 +797,7 @@ static const VMStateDescription vmstate_cuda = {VMSTATE_INT32 (data_in_index, CUDAState),VMSTATE_INT32 (data_out_index, CUDAState),VMSTATE_UINT8 (autopoll, CUDAState), +VMSTATE_UINT8 (autopoll_rate_ms, CUDAState),VMSTATE_BUFFER (data_in, CUDAState),VMSTATE_BUFFER (data_out, CUDAState), VMSTATE_UINT32(tick_offset, CUDAState),
@@ -828,6 +851,7 @@ static void cuda_realizefn(DeviceState *dev, Error **errp) s->tick_offset = (uint32_t )mktimegm (&tm) +RTC_OFFSET ; s->adb_poll_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , cuda_adb_poll, s); + s->autopoll_rate_ms =20 ; }static void cuda_initfn (Object *obj)
hw/ppc/mac.h +1 -0
@@ -111,6 +111,7 @@ typedef struct CUDAState {int data_out_index;qemu_irq irq; +uint8_t autopoll_rate_ms;uint8_t autopoll;uint8_t data_in[128 ];uint8_t data_out[16 ];
Signature · 1 line
2.1.4
PATCH v2 5/13 cuda: port SET_DEVICE_LIST command to new framework
In reply to Hervé PoussineauAlso implement the command, by taking device list mask into account when polling ADB devices.
--- hw/input/adb.c | 18 ++++++++++-------- hw/misc/macio/cuda.c | 18 ++++++++++++++++-- hw/ppc/mac.h | 1 + include/hw/input/adb.h | 2 +- 4 files changed, 28 insertions(+), 11 deletions(-)
hw/input/adb.c +10 -8
@@ -89,7 +89,7 @@ int adb_request(ADBBusState *s, uint8_t *obuf, const uint8_t *buf, int len) }/* XXX: move that to cuda ? */ -int adb_poll (ADBBusState *s,uint8_t *obuf) +int adb_poll (ADBBusState *s,uint8_t *obuf,uint16_t poll_mask) {ADBDevice *d;int olen, i;
@@ -100,13 +100,15 @@ int adb_poll(ADBBusState *s, uint8_t *obuf)if (s->poll_index >= s->nb_devices) s->poll_index =0 ; d = s->devices[s->poll_index]; - buf[0 ] =ADB_READREG | (d->devaddr <<4 ); - olen =adb_request (s, obuf +1 , buf,1 ); -/* if there is data, we poll again the same device */ -if (olen >0 ) { - obuf[0 ] = buf[0 ]; - olen++; -break ; +if ((1 << d->devaddr) & poll_mask) { + buf[0 ] =ADB_READREG | (d->devaddr <<4 ); + olen =adb_request (s, obuf +1 , buf,1 ); +/* if there is data, we poll again the same device */ +if (olen >0 ) { + obuf[0 ] = buf[0 ]; + olen++; +break ; + } } s->poll_index++; }
hw/misc/macio/cuda.c +16 -2
@@ -523,7 +523,7 @@ static void cuda_adb_poll(void *opaque)uint8_t obuf[ADB_MAX_OUT_LEN +2 ];int olen; - olen =adb_poll (&s->adb_bus, obuf +2 ); + olen =adb_poll (&s->adb_bus, obuf +2 , s->adb_poll_mask);if (olen >0 ) { obuf[0 ] =ADB_PACKET ; obuf[1 ] =0x40 ;/* polled data */
@@ -590,9 +590,22 @@ static bool cuda_cmd_set_autorate(CUDAState *s,return true; } +static bool cuda_cmd_set_device_list (CUDAState *s, +const uint8_t *in_data,int in_len, +uint8_t *out_data,int *out_len) +{ +if (in_len !=2 ) { +return false; + } + + s->adb_poll_mask = (((uint16_t )in_data[0 ]) <<8 ) | in_data[1 ]; +return true; +} +static const CudaCommand handlers[] = { {CUDA_AUTOPOLL ,"AUTOPOLL" , cuda_cmd_autopoll }, {CUDA_SET_AUTO_RATE ,"SET_AUTO_RATE" , cuda_cmd_set_autorate }, + {CUDA_SET_DEVICE_LIST ,"SET_DEVICE_LIST" , cuda_cmd_set_device_list }, }; static void cuda_receive_packet(CUDAState *s,
@@ -641,7 +654,6 @@ static void cuda_receive_packet(CUDAState *s,cuda_send_packet_to_host (s, obuf,7 );return ;case CUDA_FILE_SERVER_FLAG : -case CUDA_SET_DEVICE_LIST :case CUDA_SET_POWER_MESSAGES :cuda_send_packet_to_host (s, obuf,3 );return ;
@@ -798,6 +810,7 @@ static const VMStateDescription vmstate_cuda = {VMSTATE_INT32 (data_out_index, CUDAState),VMSTATE_UINT8 (autopoll, CUDAState),VMSTATE_UINT8 (autopoll_rate_ms, CUDAState), +VMSTATE_UINT16 (adb_poll_mask, CUDAState),VMSTATE_BUFFER (data_in, CUDAState),VMSTATE_BUFFER (data_out, CUDAState), VMSTATE_UINT32(tick_offset, CUDAState),
@@ -852,6 +865,7 @@ static void cuda_realizefn(DeviceState *dev, Error **errp) s->adb_poll_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , cuda_adb_poll, s); s->autopoll_rate_ms =20 ; + s->adb_poll_mask =0xffff ; }static void cuda_initfn (Object *obj)
hw/ppc/mac.h +1 -0
@@ -111,6 +111,7 @@ typedef struct CUDAState {int data_out_index;qemu_irq irq; +uint16_t adb_poll_mask;uint8_t autopoll_rate_ms;uint8_t autopoll;uint8_t data_in[128 ];
include/hw/input/adb.h +1 -1
@@ -79,7 +79,7 @@ struct ADBBusState {int adb_request (ADBBusState *s,uint8_t *buf_out,const uint8_t *buf,int len); -int adb_poll (ADBBusState *s,uint8_t *buf_out); +int adb_poll (ADBBusState *s,uint8_t *buf_out,uint16_t poll_mask);#define TYPE_ADB_KEYBOARD "adb-keyboard"#define TYPE_ADB_MOUSE "adb-mouse"
Signature · 1 line
2.1.4
PATCH v2 6/13 cuda: port POWERDOWN command to new framework
In reply to Hervé Poussineau--- hw/misc/macio/cuda.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
hw/misc/macio/cuda.c +13 -4
@@ -602,10 +602,23 @@ static bool cuda_cmd_set_device_list(CUDAState *s,return true; } +static bool cuda_cmd_powerdown (CUDAState *s, +const uint8_t *in_data,int in_len, +uint8_t *out_data,int *out_len) +{ +if (in_len !=0 ) { +return false; + } + +qemu_system_shutdown_request (); +return true; +} +static const CudaCommand handlers[] = { {CUDA_AUTOPOLL ,"AUTOPOLL" , cuda_cmd_autopoll }, {CUDA_SET_AUTO_RATE ,"SET_AUTO_RATE" , cuda_cmd_set_autorate }, {CUDA_SET_DEVICE_LIST ,"SET_DEVICE_LIST" , cuda_cmd_set_device_list }, + {CUDA_POWERDOWN ,"POWERDOWN" , cuda_cmd_powerdown }, }; static void cuda_receive_packet(CUDAState *s,
@@ -657,10 +670,6 @@ static void cuda_receive_packet(CUDAState *s,case CUDA_SET_POWER_MESSAGES :cuda_send_packet_to_host (s, obuf,3 );return ; -case CUDA_POWERDOWN : -cuda_send_packet_to_host (s, obuf,3 ); -qemu_system_shutdown_request (); -return ;case CUDA_RESET_SYSTEM :cuda_send_packet_to_host (s, obuf,3 );qemu_system_reset_request ();
Signature · 1 line
2.1.4
PATCH v2 7/13 cuda: port RESET_SYSTEM command to new framework
In reply to Hervé Poussineau--- hw/misc/macio/cuda.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
hw/misc/macio/cuda.c +13 -4
@@ -614,11 +614,24 @@ static bool cuda_cmd_powerdown(CUDAState *s,return true; } +static bool cuda_cmd_reset_system (CUDAState *s, +const uint8_t *in_data,int in_len, +uint8_t *out_data,int *out_len) +{ +if (in_len !=0 ) { +return false; + } + +qemu_system_reset_request (); +return true; +} +static const CudaCommand handlers[] = { {CUDA_AUTOPOLL ,"AUTOPOLL" , cuda_cmd_autopoll }, {CUDA_SET_AUTO_RATE ,"SET_AUTO_RATE" , cuda_cmd_set_autorate }, {CUDA_SET_DEVICE_LIST ,"SET_DEVICE_LIST" , cuda_cmd_set_device_list }, {CUDA_POWERDOWN ,"POWERDOWN" , cuda_cmd_powerdown }, + {CUDA_RESET_SYSTEM ,"RESET_SYSTEM" , cuda_cmd_reset_system }, }; static void cuda_receive_packet(CUDAState *s,
@@ -670,10 +683,6 @@ static void cuda_receive_packet(CUDAState *s,case CUDA_SET_POWER_MESSAGES :cuda_send_packet_to_host (s, obuf,3 );return ; -case CUDA_RESET_SYSTEM : -cuda_send_packet_to_host (s, obuf,3 ); -qemu_system_reset_request (); -return ;case CUDA_COMBINED_FORMAT_IIC : obuf[0 ] =ERROR_PACKET ; obuf[1 ] =0x5 ;
Signature · 1 line
2.1.4
PATCH v2 8/13 cuda: port FILE_SERVER_FLAG command to new framework
In reply to Hervé PoussineauThis command tells if computer should automatically wake-up after a power loss.
--- hw/misc/macio/cuda.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
hw/misc/macio/cuda.c +16 -1
@@ -626,12 +626,28 @@ static bool cuda_cmd_reset_system(CUDAState *s,return true; } +static bool cuda_cmd_set_file_server_flag (CUDAState *s, +const uint8_t *in_data,int in_len, +uint8_t *out_data,int *out_len) +{ +if (in_len !=1 ) { +return false; + } + +qemu_log_mask (LOG_UNIMP , +"CUDA: unimplemented command FILE_SERVER_FLAG %d\n" , + in_data[0 ]); +return true; +} +static const CudaCommand handlers[] = { {CUDA_AUTOPOLL ,"AUTOPOLL" , cuda_cmd_autopoll }, {CUDA_SET_AUTO_RATE ,"SET_AUTO_RATE" , cuda_cmd_set_autorate }, {CUDA_SET_DEVICE_LIST ,"SET_DEVICE_LIST" , cuda_cmd_set_device_list }, {CUDA_POWERDOWN ,"POWERDOWN" , cuda_cmd_powerdown }, {CUDA_RESET_SYSTEM ,"RESET_SYSTEM" , cuda_cmd_reset_system }, + {CUDA_FILE_SERVER_FLAG ,"FILE_SERVER_FLAG" , + cuda_cmd_set_file_server_flag }, }; static void cuda_receive_packet(CUDAState *s,
@@ -679,7 +695,6 @@ static void cuda_receive_packet(CUDAState *s, obuf[6 ] = ti;cuda_send_packet_to_host (s, obuf,7 );return ; -case CUDA_FILE_SERVER_FLAG :case CUDA_SET_POWER_MESSAGES :cuda_send_packet_to_host (s, obuf,3 );return ;
Signature · 1 line
2.1.4
PATCH v2 9/13 cuda: port SET_POWER_MESSAGES command to new framework
In reply to Hervé Poussineau--- hw/misc/macio/cuda.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
hw/misc/macio/cuda.c +16 -3
@@ -640,6 +640,20 @@ static bool cuda_cmd_set_file_server_flag(CUDAState *s,return true; } +static bool cuda_cmd_set_power_message (CUDAState *s, +const uint8_t *in_data,int in_len, +uint8_t *out_data,int *out_len) +{ +if (in_len !=1 ) { +return false; + } + +qemu_log_mask (LOG_UNIMP , +"CUDA: unimplemented command SET_POWER_MESSAGE %d\n" , + in_data[0 ]); +return true; +} +static const CudaCommand handlers[] = { {CUDA_AUTOPOLL ,"AUTOPOLL" , cuda_cmd_autopoll }, {CUDA_SET_AUTO_RATE ,"SET_AUTO_RATE" , cuda_cmd_set_autorate },
@@ -648,6 +662,8 @@ static const CudaCommand handlers[] = { { CUDA_RESET_SYSTEM, "RESET_SYSTEM", cuda_cmd_reset_system }, { CUDA_FILE_SERVER_FLAG, "FILE_SERVER_FLAG", cuda_cmd_set_file_server_flag }, + { CUDA_SET_POWER_MESSAGES, "SET_POWER_MESSAGES", + cuda_cmd_set_power_message }, }; static void cuda_receive_packet(CUDAState *s,
@@ -695,9 +711,6 @@ static void cuda_receive_packet(CUDAState *s, obuf[6 ] = ti;cuda_send_packet_to_host (s, obuf,7 );return ; -case CUDA_SET_POWER_MESSAGES : -cuda_send_packet_to_host (s, obuf,3 ); -return ;case CUDA_COMBINED_FORMAT_IIC : obuf[0 ] =ERROR_PACKET ; obuf[1 ] =0x5 ;
Signature · 1 line
2.1.4
PATCH v2 10/13 cuda: port GET_TIME command to new framework
In reply to Hervé Poussineau--- hw/misc/macio/cuda.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-)
hw/misc/macio/cuda.c +21 -8
@@ -654,6 +654,26 @@ static bool cuda_cmd_set_power_message(CUDAState *s,return true; } +static bool cuda_cmd_get_time (CUDAState *s, +const uint8_t *in_data,int in_len, +uint8_t *out_data,int *out_len) +{ +uint32_t ti; + +if (in_len !=0 ) { +return false; + } + + ti = s->tick_offset + (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + /get_ticks_per_sec ()); + out_data[0 ] = ti >>24 ; + out_data[1 ] = ti >>16 ; + out_data[2 ] = ti >>8 ; + out_data[3 ] = ti; + *out_len =4 ; +return true; +} +static const CudaCommand handlers[] = { {CUDA_AUTOPOLL ,"AUTOPOLL" , cuda_cmd_autopoll }, {CUDA_SET_AUTO_RATE ,"SET_AUTO_RATE" , cuda_cmd_set_autorate },
@@ -664,6 +684,7 @@ static const CudaCommand handlers[] = { cuda_cmd_set_file_server_flag }, { CUDA_SET_POWER_MESSAGES, "SET_POWER_MESSAGES", cuda_cmd_set_power_message }, + { CUDA_GET_TIME, "GET_TIME", cuda_cmd_get_time }, }; static void cuda_receive_packet(CUDAState *s,
@@ -703,14 +724,6 @@ static void cuda_receive_packet(CUDAState *s, s->tick_offset = ti - (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) /get_ticks_per_sec ());cuda_send_packet_to_host (s, obuf,3 );return ; -case CUDA_GET_TIME : - ti = s->tick_offset + (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) /get_ticks_per_sec ()); - obuf[3 ] = ti >>24 ; - obuf[4 ] = ti >>16 ; - obuf[5 ] = ti >>8 ; - obuf[6 ] = ti; -cuda_send_packet_to_host (s, obuf,7 ); -return ;case CUDA_COMBINED_FORMAT_IIC : obuf[0 ] =ERROR_PACKET ; obuf[1 ] =0x5 ;
Signature · 1 line
2.1.4
PATCH v2 11/13 cuda: port SET_TIME command to new framework
In reply to Hervé Poussineau--- hw/misc/macio/cuda.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)
hw/misc/macio/cuda.c +18 -6
@@ -674,6 +674,23 @@ static bool cuda_cmd_get_time(CUDAState *s,return true; } +static bool cuda_cmd_set_time (CUDAState *s, +const uint8_t *in_data,int in_len, +uint8_t *out_data,int *out_len) +{ +uint32_t ti; + +if (in_len !=4 ) { +return false; + } + + ti = (((uint32_t )in_data[1 ]) <<24 ) + (((uint32_t )in_data[2 ]) <<16 ) + + (((uint32_t )in_data[3 ]) <<8 ) + in_data[4 ]; + s->tick_offset = ti - (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + /get_ticks_per_sec ()); +return true; +} +static const CudaCommand handlers[] = { {CUDA_AUTOPOLL ,"AUTOPOLL" , cuda_cmd_autopoll }, {CUDA_SET_AUTO_RATE ,"SET_AUTO_RATE" , cuda_cmd_set_autorate },
@@ -685,6 +702,7 @@ static const CudaCommand handlers[] = { {CUDA_SET_POWER_MESSAGES ,"SET_POWER_MESSAGES" , cuda_cmd_set_power_message }, { CUDA_GET_TIME, "GET_TIME", cuda_cmd_get_time }, + { CUDA_SET_TIME, "SET_TIME", cuda_cmd_set_time }, }; static void cuda_receive_packet(CUDAState *s,
@@ -692,7 +710,6 @@ static void cuda_receive_packet(CUDAState *s, {uint8_t obuf[16 ] = {CUDA_PACKET ,0 , data[0 ] };int i, out_len =0 ; -uint32_t ti;for (i =0 ; i <ARRAY_SIZE (handlers); i++) {const CudaCommand *desc = &handlers[i];
@@ -719,11 +736,6 @@ static void cuda_receive_packet(CUDAState *s,case CUDA_GET_6805_ADDR :cuda_send_packet_to_host (s, obuf,3 );return ; -case CUDA_SET_TIME : - ti = (((uint32_t )data[1 ]) <<24 ) + (((uint32_t )data[2 ]) <<16 ) + (((uint32_t )data[3 ]) <<8 ) + data[4 ]; - s->tick_offset = ti - (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) /get_ticks_per_sec ()); -cuda_send_packet_to_host (s, obuf,3 ); -return ;case CUDA_COMBINED_FORMAT_IIC : obuf[0 ] =ERROR_PACKET ; obuf[1 ] =0x5 ;
Signature · 1 line
2.1.4
PATCH v2 12/13 cuda: remove GET_6805_ADDR command
In reply to Hervé PoussineauIt doesn't seem to be used, and operating systems should accept a 'unknown command' answer.
--- hw/misc/macio/cuda.c | 3 --- 1 file changed, 3 deletions(-)
hw/misc/macio/cuda.c +0 -3
@@ -733,9 +733,6 @@ static void cuda_receive_packet(CUDAState *s, }switch (data[0 ]) { -case CUDA_GET_6805_ADDR : -cuda_send_packet_to_host (s, obuf,3 ); -return ;case CUDA_COMBINED_FORMAT_IIC : obuf[0 ] =ERROR_PACKET ; obuf[1 ] =0x5 ;
Signature · 1 line
2.1.4
PATCH v2 13/13 cuda: remove CUDA_GET_SET_IIC/CUDA_COMBINED_FORMAT_IIC commands
In reply to Hervé PoussineauWe currently don't emulate the I2C bus provided by CUDA.
--- hw/misc/macio/cuda.c | 23 ----------------------- 1 file changed, 23 deletions(-)
hw/misc/macio/cuda.c +0 -23
@@ -732,29 +732,6 @@ static void cuda_receive_packet(CUDAState *s, } } -switch (data[0 ]) { -case CUDA_COMBINED_FORMAT_IIC : - obuf[0 ] =ERROR_PACKET ; - obuf[1 ] =0x5 ; - obuf[2 ] =CUDA_PACKET ; - obuf[3 ] = data[0 ]; -cuda_send_packet_to_host (s, obuf,4 ); -return ; -case CUDA_GET_SET_IIC : -if (len ==4 ) { -cuda_send_packet_to_host (s, obuf,3 ); - }else { - obuf[0 ] =ERROR_PACKET ; - obuf[1 ] =0x2 ; - obuf[2 ] =CUDA_PACKET ; - obuf[3 ] = data[0 ]; -cuda_send_packet_to_host (s, obuf,4 ); - } -return ; -default : -break ; - } -qemu_log_mask (LOG_GUEST_ERROR ,"CUDA: unknown command 0x%02x\n" , data[0 ]); obuf[0 ] =ERROR_PACKET ; obuf[1 ] =0x2 ;/* unknown command */
Signature · 1 line
2.1.4
Quoted 30 lines · Hervé Poussineau
Hi,
This patchset cleans up a little bit the Apple CUDA emulation:
- correctly reject commands with wrong parameters
- support changing the frequency of auto-polling
- support changing device list probed in auto-poll
- add logs when using FILE_SERVER_FLAG/SET_POWER_MESSAGE
- remove unused commands (GET/SET_6805_ADDR)
- remove unimplemented GET_SET_IIC/COMBINED_FORMAT_IICGET_SET_IIC/COMBINED_FORMAT_IIC commands should be added again once we implement the I2C bus provided by CUDA.
Hervé
Hervé Poussineau (13):
cuda: add a framework to handle commands
cuda: move unknown commands reject out of switch
cuda: port AUTOPOLL command to new framework
cuda: portSET_AUTO_RATEcommand to new framework
cuda: portSET_DEVICE_LISTcommand to new framework
cuda: port POWERDOWN command to new framework
cuda: portRESET_SYSTEMcommand to new framework
cuda: portFILE_SERVER_FLAGcommand to new framework
cuda: portSET_POWER_MESSAGEScommand to new framework
cuda: portGET_TIMEcommand to new framework
cuda: portSET_TIMEcommand to new framework
cuda: removeGET_6805_ADDRcommand
cuda: remove CUDA_GET_SET_IIC/CUDA_COMBINED_FORMAT_IIC commands
Quoted 5 lines
hw/input/adb.c | 18 ++-- hw/misc/macio/cuda.c | 279 ++++++++++++++++++++++++++++++++++++------------- hw/ppc/mac.h | 2 + include/hw/input/adb.h | 2 +- 4 files changed, 217 insertions(+), 84 deletions(-)
This looks good to me, and again passes all my local tests. The only thing I noticed was that there were no changes related to qemu_log_mask() as per David's comments on patch 2 but other than that I think this patchset is fine to merge for 2.6.
ATB,
Mark.
Quoted 38 lines · Mark Cave-Ayland
Quoted 30 lines · Hervé Poussineau
Hi,
This patchset cleans up a little bit the Apple CUDA emulation:
- correctly reject commands with wrong parameters
- support changing the frequency of auto-polling
- support changing device list probed in auto-poll
- add logs when using FILE_SERVER_FLAG/SET_POWER_MESSAGE
- remove unused commands (GET/SET_6805_ADDR)
- remove unimplemented GET_SET_IIC/COMBINED_FORMAT_IICGET_SET_IIC/COMBINED_FORMAT_IIC commands should be added again once we implement the I2C bus provided by CUDA.
Hervé
Hervé Poussineau (13):
cuda: add a framework to handle commands
cuda: move unknown commands reject out of switch
cuda: port AUTOPOLL command to new framework
cuda: portSET_AUTO_RATEcommand to new framework
cuda: portSET_DEVICE_LISTcommand to new framework
cuda: port POWERDOWN command to new framework
cuda: portRESET_SYSTEMcommand to new framework
cuda: portFILE_SERVER_FLAGcommand to new framework
cuda: portSET_POWER_MESSAGEScommand to new framework
cuda: portGET_TIMEcommand to new framework
cuda: portSET_TIMEcommand to new framework
cuda: removeGET_6805_ADDRcommand
cuda: remove CUDA_GET_SET_IIC/CUDA_COMBINED_FORMAT_IIC commandsQuoted 5 lines
hw/input/adb.c | 18 ++-- hw/misc/macio/cuda.c | 279 ++++++++++++++++++++++++++++++++++++------------- hw/ppc/mac.h | 2 + include/hw/input/adb.h | 2 +- 4 files changed, 217 insertions(+), 84 deletions(-)
Quoted 6 lines
Reviewed-by Mark Cave-Ayland <[email protected]>This looks good to me, and again passes all my local tests. The only thing I noticed was that there were no changes related to
qemu_log_mask()as per David's comments on patch 2 but other than that I think this patchset is fine to merge for 2.6.
qemu_log_mask() doesn't represent the same thing than trace events, even if they can go to the same output file. I always run QEMU with -d guest_errors,unimp to see if something wrong happens on guest side. I have no knowledge of all traces in all devices, to know which ones are important at first run. However, if I want to detail one device behaviour, I can enable specific traces for this device.
Note also that new qemu_log_mask() calls are added, like in cc28296d82ce179e81ee6d0b9cfb7f6a79ffc1c6
Hervé
Quoted 38 lines · Mark Cave-Ayland
Quoted 30 lines · Hervé Poussineau
Hi,
This patchset cleans up a little bit the Apple CUDA emulation:
- correctly reject commands with wrong parameters
- support changing the frequency of auto-polling
- support changing device list probed in auto-poll
- add logs when using FILE_SERVER_FLAG/SET_POWER_MESSAGE
- remove unused commands (GET/SET_6805_ADDR)
- remove unimplemented GET_SET_IIC/COMBINED_FORMAT_IICGET_SET_IIC/COMBINED_FORMAT_IIC commands should be added again once we implement the I2C bus provided by CUDA.
Hervé
Hervé Poussineau (13):
cuda: add a framework to handle commands
cuda: move unknown commands reject out of switch
cuda: port AUTOPOLL command to new framework
cuda: portSET_AUTO_RATEcommand to new framework
cuda: portSET_DEVICE_LISTcommand to new framework
cuda: port POWERDOWN command to new framework
cuda: portRESET_SYSTEMcommand to new framework
cuda: portFILE_SERVER_FLAGcommand to new framework
cuda: portSET_POWER_MESSAGEScommand to new framework
cuda: portGET_TIMEcommand to new framework
cuda: portSET_TIMEcommand to new framework
cuda: removeGET_6805_ADDRcommand
cuda: remove CUDA_GET_SET_IIC/CUDA_COMBINED_FORMAT_IIC commandsQuoted 5 lines
hw/input/adb.c | 18 ++-- hw/misc/macio/cuda.c | 279 ++++++++++++++++++++++++++++++++++++------------- hw/ppc/mac.h | 2 + include/hw/input/adb.h | 2 +- 4 files changed, 217 insertions(+), 84 deletions(-)
Quoted 6 lines
Reviewed-by Mark Cave-Ayland <[email protected]>This looks good to me, and again passes all my local tests. The only thing I noticed was that there were no changes related to
qemu_log_mask()as per David's comments on patch 2 but other than that I think this patchset is fine to merge for 2.6.
Thanks for this, I've merged the series to ppc-for-2.6.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson