11e8a1faeSThomas Huth /*
21e8a1faeSThomas Huth * QTest testcase for USB UHCI controller
31e8a1faeSThomas Huth *
41e8a1faeSThomas Huth * Copyright (c) 2014 HUAWEI TECHNOLOGIES CO., LTD.
51e8a1faeSThomas Huth *
61e8a1faeSThomas Huth * This work is licensed under the terms of the GNU GPL, version 2 or later.
71e8a1faeSThomas Huth * See the COPYING file in the top-level directory.
81e8a1faeSThomas Huth */
91e8a1faeSThomas Huth
101e8a1faeSThomas Huth #include "qemu/osdep.h"
111e8a1faeSThomas Huth #include "libqtest-single.h"
121e8a1faeSThomas Huth #include "libqos/libqos.h"
131e8a1faeSThomas Huth #include "libqos/usb.h"
141e8a1faeSThomas Huth #include "libqos/libqos-pc.h"
151e8a1faeSThomas Huth #include "libqos/libqos-spapr.h"
161e8a1faeSThomas Huth #include "hw/usb/uhci-regs.h"
171e8a1faeSThomas Huth
181e8a1faeSThomas Huth static QOSState *qs;
191e8a1faeSThomas Huth
test_port(int port)201e8a1faeSThomas Huth static void test_port(int port)
211e8a1faeSThomas Huth {
221e8a1faeSThomas Huth struct qhc uhci;
231e8a1faeSThomas Huth
241e8a1faeSThomas Huth g_assert(port > 0);
251e8a1faeSThomas Huth qusb_pci_init_one(qs->pcibus, &uhci, QPCI_DEVFN(0x1d, 0), 4);
261e8a1faeSThomas Huth uhci_port_test(&uhci, port - 1, UHCI_PORT_CCS);
271e8a1faeSThomas Huth uhci_deinit(&uhci);
281e8a1faeSThomas Huth }
291e8a1faeSThomas Huth
test_port_1(void)301e8a1faeSThomas Huth static void test_port_1(void)
311e8a1faeSThomas Huth {
321e8a1faeSThomas Huth test_port(1);
331e8a1faeSThomas Huth }
341e8a1faeSThomas Huth
test_port_2(void)351e8a1faeSThomas Huth static void test_port_2(void)
361e8a1faeSThomas Huth {
371e8a1faeSThomas Huth test_port(2);
381e8a1faeSThomas Huth }
391e8a1faeSThomas Huth
test_uhci_hotplug(void)401e8a1faeSThomas Huth static void test_uhci_hotplug(void)
411e8a1faeSThomas Huth {
421e8a1faeSThomas Huth usb_test_hotplug(global_qtest, "uhci", "2", test_port_2);
431e8a1faeSThomas Huth }
441e8a1faeSThomas Huth
test_usb_storage_hotplug(void)451e8a1faeSThomas Huth static void test_usb_storage_hotplug(void)
461e8a1faeSThomas Huth {
471e8a1faeSThomas Huth QTestState *qts = global_qtest;
481e8a1faeSThomas Huth
491e8a1faeSThomas Huth qtest_qmp_device_add(qts, "usb-storage", "usbdev0", "{'drive': 'drive0'}");
501e8a1faeSThomas Huth
511e8a1faeSThomas Huth qtest_qmp_device_del(qts, "usbdev0");
521e8a1faeSThomas Huth }
531e8a1faeSThomas Huth
main(int argc,char ** argv)541e8a1faeSThomas Huth int main(int argc, char **argv)
551e8a1faeSThomas Huth {
561e8a1faeSThomas Huth const char *arch = qtest_get_arch();
571e8a1faeSThomas Huth const char *cmd = "-device piix3-usb-uhci,id=uhci,addr=1d.0"
581e8a1faeSThomas Huth " -drive id=drive0,if=none,file=null-co://,"
591e8a1faeSThomas Huth "file.read-zeroes=on,format=raw"
601e8a1faeSThomas Huth " -device usb-tablet,bus=uhci.0,port=1";
611e8a1faeSThomas Huth int ret;
621e8a1faeSThomas Huth
631e8a1faeSThomas Huth g_test_init(&argc, &argv, NULL);
641e8a1faeSThomas Huth
659b76fc5aSThomas Huth if (!qtest_has_device("piix3-usb-uhci")) {
669b76fc5aSThomas Huth g_debug("piix3-usb-uhci not available");
679b76fc5aSThomas Huth return 0;
689b76fc5aSThomas Huth }
699b76fc5aSThomas Huth
701e8a1faeSThomas Huth qtest_add_func("/uhci/pci/port1", test_port_1);
711e8a1faeSThomas Huth qtest_add_func("/uhci/pci/hotplug", test_uhci_hotplug);
72*54c8ff27SThomas Huth if (qtest_has_device("usb-storage")) {
731e8a1faeSThomas Huth qtest_add_func("/uhci/pci/hotplug/usb-storage", test_usb_storage_hotplug);
74*54c8ff27SThomas Huth }
751e8a1faeSThomas Huth
761e8a1faeSThomas Huth if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
770472b2e5SDaniel P. Berrangé qs = qtest_pc_boot("%s", cmd);
781e8a1faeSThomas Huth } else if (strcmp(arch, "ppc64") == 0) {
790472b2e5SDaniel P. Berrangé qs = qtest_spapr_boot("%s", cmd);
801e8a1faeSThomas Huth } else {
811e8a1faeSThomas Huth g_printerr("usb-hcd-uhci-test tests are only "
821e8a1faeSThomas Huth "available on x86 or ppc64\n");
831e8a1faeSThomas Huth exit(EXIT_FAILURE);
841e8a1faeSThomas Huth }
851e8a1faeSThomas Huth global_qtest = qs->qts;
861e8a1faeSThomas Huth ret = g_test_run();
871e8a1faeSThomas Huth qtest_shutdown(qs);
881e8a1faeSThomas Huth
891e8a1faeSThomas Huth return ret;
901e8a1faeSThomas Huth }
91