Commit 6c319c82223a1766c5d64a20051e5c6ab7b53951
1 parent
2582cfa0
Sparc32/PPC: convert escc to qdev
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
Showing
1 changed file
with
97 additions
and
57 deletions
hw/escc.c
... | ... | @@ -21,7 +21,9 @@ |
21 | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
22 | 22 | * THE SOFTWARE. |
23 | 23 | */ |
24 | + | |
24 | 25 | #include "hw.h" |
26 | +#include "sysbus.h" | |
25 | 27 | #include "escc.h" |
26 | 28 | #include "qemu-char.h" |
27 | 29 | #include "console.h" |
... | ... | @@ -114,8 +116,10 @@ typedef struct ChannelState { |
114 | 116 | } ChannelState; |
115 | 117 | |
116 | 118 | struct SerialState { |
119 | + SysBusDevice busdev; | |
117 | 120 | struct ChannelState chn[2]; |
118 | 121 | int it_shift; |
122 | + int mmio_index; | |
119 | 123 | }; |
120 | 124 | |
121 | 125 | #define SERIAL_CTRL 0 |
... | ... | @@ -723,44 +727,28 @@ int escc_init(target_phys_addr_t base, qemu_irq irqA, qemu_irq irqB, |
723 | 727 | CharDriverState *chrA, CharDriverState *chrB, |
724 | 728 | int clock, int it_shift) |
725 | 729 | { |
726 | - int escc_io_memory, i; | |
727 | - SerialState *s; | |
728 | - | |
729 | - s = qemu_mallocz(sizeof(SerialState)); | |
730 | - | |
731 | - escc_io_memory = cpu_register_io_memory(escc_mem_read, | |
732 | - escc_mem_write, | |
733 | - s); | |
734 | - if (base) | |
735 | - cpu_register_physical_memory(base, ESCC_SIZE << it_shift, | |
736 | - escc_io_memory); | |
737 | - | |
738 | - s->it_shift = it_shift; | |
739 | - s->chn[0].chr = chrB; | |
740 | - s->chn[1].chr = chrA; | |
741 | - s->chn[0].disabled = 0; | |
742 | - s->chn[1].disabled = 0; | |
743 | - s->chn[0].irq = irqB; | |
744 | - s->chn[1].irq = irqA; | |
745 | - | |
746 | - for (i = 0; i < 2; i++) { | |
747 | - s->chn[i].chn = 1 - i; | |
748 | - s->chn[i].type = ser; | |
749 | - s->chn[i].clock = clock / 2; | |
750 | - if (s->chn[i].chr) { | |
751 | - qemu_chr_add_handlers(s->chn[i].chr, serial_can_receive, | |
752 | - serial_receive1, serial_event, &s->chn[i]); | |
753 | - } | |
730 | + DeviceState *dev; | |
731 | + SysBusDevice *s; | |
732 | + SerialState *d; | |
733 | + | |
734 | + dev = qdev_create(NULL, "escc"); | |
735 | + qdev_set_prop_int(dev, "disabled", 0); | |
736 | + qdev_set_prop_int(dev, "frequency", clock); | |
737 | + qdev_set_prop_int(dev, "it_shift", it_shift); | |
738 | + qdev_set_prop_ptr(dev, "chrB", chrB); | |
739 | + qdev_set_prop_ptr(dev, "chrA", chrA); | |
740 | + qdev_set_prop_int(dev, "chnBtype", ser); | |
741 | + qdev_set_prop_int(dev, "chnAtype", ser); | |
742 | + qdev_init(dev); | |
743 | + s = sysbus_from_qdev(dev); | |
744 | + sysbus_connect_irq(s, 0, irqA); | |
745 | + sysbus_connect_irq(s, 1, irqB); | |
746 | + if (base) { | |
747 | + sysbus_mmio_map(s, 0, base); | |
754 | 748 | } |
755 | - s->chn[0].otherchn = &s->chn[1]; | |
756 | - s->chn[1].otherchn = &s->chn[0]; | |
757 | - if (base) | |
758 | - register_savevm("escc", base, 2, escc_save, escc_load, s); | |
759 | - else | |
760 | - register_savevm("escc", -1, 2, escc_save, escc_load, s); | |
761 | - qemu_register_reset(escc_reset, s); | |
762 | - escc_reset(s); | |
763 | - return escc_io_memory; | |
749 | + | |
750 | + d = FROM_SYSBUS(SerialState, s); | |
751 | + return d->mmio_index; | |
764 | 752 | } |
765 | 753 | |
766 | 754 | static const uint8_t keycodes[128] = { |
... | ... | @@ -903,35 +891,87 @@ static void sunmouse_event(void *opaque, |
903 | 891 | void slavio_serial_ms_kbd_init(target_phys_addr_t base, qemu_irq irq, |
904 | 892 | int disabled, int clock, int it_shift) |
905 | 893 | { |
906 | - int slavio_serial_io_memory, i; | |
907 | - SerialState *s; | |
908 | - | |
909 | - s = qemu_mallocz(sizeof(SerialState)); | |
894 | + DeviceState *dev; | |
895 | + SysBusDevice *s; | |
896 | + | |
897 | + dev = qdev_create(NULL, "escc"); | |
898 | + qdev_set_prop_int(dev, "disabled", disabled); | |
899 | + qdev_set_prop_int(dev, "frequency", clock); | |
900 | + qdev_set_prop_int(dev, "it_shift", it_shift); | |
901 | + qdev_set_prop_ptr(dev, "chrB", NULL); | |
902 | + qdev_set_prop_ptr(dev, "chrA", NULL); | |
903 | + qdev_set_prop_int(dev, "chnBtype", mouse); | |
904 | + qdev_set_prop_int(dev, "chnAtype", kbd); | |
905 | + qdev_init(dev); | |
906 | + s = sysbus_from_qdev(dev); | |
907 | + sysbus_connect_irq(s, 0, irq); | |
908 | + sysbus_connect_irq(s, 1, irq); | |
909 | + sysbus_mmio_map(s, 0, base); | |
910 | +} | |
910 | 911 | |
911 | - s->it_shift = it_shift; | |
912 | +static void escc_init1(SysBusDevice *dev) | |
913 | +{ | |
914 | + SerialState *s = FROM_SYSBUS(SerialState, dev); | |
915 | + int io; | |
916 | + unsigned int i; | |
917 | + uint32_t clock, disabled; | |
918 | + | |
919 | + s->it_shift = qdev_get_prop_int(&dev->qdev, "it_shift", 0); | |
920 | + clock = qdev_get_prop_int(&dev->qdev, "frequency", 0); | |
921 | + s->chn[0].chr = qdev_get_prop_ptr(&dev->qdev, "chrB"); | |
922 | + s->chn[1].chr = qdev_get_prop_ptr(&dev->qdev, "chrA"); | |
923 | + disabled = qdev_get_prop_int(&dev->qdev, "disabled", 0); | |
924 | + s->chn[0].disabled = disabled; | |
925 | + s->chn[1].disabled = disabled; | |
912 | 926 | for (i = 0; i < 2; i++) { |
913 | - s->chn[i].irq = irq; | |
927 | + sysbus_init_irq(dev, &s->chn[i].irq); | |
914 | 928 | s->chn[i].chn = 1 - i; |
915 | - s->chn[i].chr = NULL; | |
916 | 929 | s->chn[i].clock = clock / 2; |
930 | + if (s->chn[i].chr) { | |
931 | + qemu_chr_add_handlers(s->chn[i].chr, serial_can_receive, | |
932 | + serial_receive1, serial_event, &s->chn[i]); | |
933 | + } | |
917 | 934 | } |
918 | 935 | s->chn[0].otherchn = &s->chn[1]; |
919 | 936 | s->chn[1].otherchn = &s->chn[0]; |
920 | - s->chn[0].type = mouse; | |
921 | - s->chn[1].type = kbd; | |
922 | - s->chn[0].disabled = disabled; | |
923 | - s->chn[1].disabled = disabled; | |
937 | + s->chn[0].type = qdev_get_prop_int(&dev->qdev, "chnBtype", 0); | |
938 | + s->chn[1].type = qdev_get_prop_int(&dev->qdev, "chnAtype", 0); | |
924 | 939 | |
925 | - slavio_serial_io_memory = cpu_register_io_memory(escc_mem_read, | |
926 | - escc_mem_write, | |
927 | - s); | |
928 | - cpu_register_physical_memory(base, ESCC_SIZE << it_shift, | |
929 | - slavio_serial_io_memory); | |
940 | + io = cpu_register_io_memory(escc_mem_read, escc_mem_write, s); | |
941 | + sysbus_init_mmio(dev, ESCC_SIZE << s->it_shift, io); | |
942 | + s->mmio_index = io; | |
930 | 943 | |
931 | - qemu_add_mouse_event_handler(sunmouse_event, &s->chn[0], 0, | |
932 | - "QEMU Sun Mouse"); | |
933 | - qemu_add_kbd_event_handler(sunkbd_event, &s->chn[1]); | |
934 | - register_savevm("slavio_serial_mouse", base, 2, escc_save, escc_load, s); | |
944 | + if (s->chn[0].type == mouse) { | |
945 | + qemu_add_mouse_event_handler(sunmouse_event, &s->chn[0], 0, | |
946 | + "QEMU Sun Mouse"); | |
947 | + } | |
948 | + if (s->chn[1].type == kbd) { | |
949 | + qemu_add_kbd_event_handler(sunkbd_event, &s->chn[1]); | |
950 | + } | |
951 | + register_savevm("escc", -1, 2, escc_save, escc_load, s); | |
935 | 952 | qemu_register_reset(escc_reset, s); |
936 | 953 | escc_reset(s); |
937 | 954 | } |
955 | + | |
956 | +static SysBusDeviceInfo escc_info = { | |
957 | + .init = escc_init1, | |
958 | + .qdev.name = "escc", | |
959 | + .qdev.size = sizeof(SerialState), | |
960 | + .qdev.props = (DevicePropList[]) { | |
961 | + {.name = "frequency", .type = PROP_TYPE_INT}, | |
962 | + {.name = "it_shift", .type = PROP_TYPE_INT}, | |
963 | + {.name = "disabled", .type = PROP_TYPE_INT}, | |
964 | + {.name = "chrB", .type = PROP_TYPE_PTR}, | |
965 | + {.name = "chrA", .type = PROP_TYPE_PTR}, | |
966 | + {.name = "chnBtype", .type = PROP_TYPE_INT}, | |
967 | + {.name = "chnAtype", .type = PROP_TYPE_INT}, | |
968 | + {.name = NULL} | |
969 | + } | |
970 | +}; | |
971 | + | |
972 | +static void escc_register_devices(void) | |
973 | +{ | |
974 | + sysbus_register_withprop(&escc_info); | |
975 | +} | |
976 | + | |
977 | +device_init(escc_register_devices) | ... | ... |