Esempio n. 1
0
    def gen_net_client_info(self, index):
        helpers = []
        code = {}
        for helper_name, cbtn in [
            ("link_status_changed", "LinkStatusChanged"),
            ("can_receive", "NetCanReceive"),
            ("receive", "NetReceive"),
            ("cleanup", "NetCleanup")
        ]:
            helper = self.gen_nic_helper(helper_name, cbtn, index)
            self.source.add_type(helper)
            helpers.append(helper)
            code[helper_name] = helper

        # Define relative order of helpers: link, can recv, recv, cleanup
        line_origins(helpers)

        code["type"] = Type["NET_CLIENT_DRIVER_NIC"]
        types = set([Type["NICState"]] + list(code.values()))
        code["size"] = "sizeof(NICState)"

        return Type["NetClientInfo"](
            self.net_client_info_name(index),
            initializer = Initializer(code, used_types = types),
            static = True
        )
Esempio n. 2
0
    def generate_header(self):
        self.state_struct = self.gen_state()

        self.header.add_type(self.state_struct)

        self.type_name_macros = Macro(name=self.qtn.type_macro,
                                      text='"%s"' % self.qtn.for_id_name)

        self.header.add_type(self.type_name_macros)

        self.type_cast_macro = Macro(
            name=self.qtn.for_macros,
            args=["obj"],
            text="OBJECT_CHECK({Struct}, (obj), {TYPE_MACRO})".format(
                TYPE_MACRO=self.qtn.type_macro, Struct=self.struct_name))

        self.header.add_type(self.type_cast_macro)

        line_origins(
            [self.type_name_macros, self.type_cast_macro, self.state_struct])

        for mmioN in range(0, self.mmio_num):
            size_macro = Macro(name=self.gen_Ith_mmio_size_macro_name(mmioN),
                               text=self.gen_mmio_size(
                                   self.mmio.get(mmioN, None)))

            self.header.add_type(size_macro)
            self.mmio_size_macros.append(size_macro)

        pio_def_size = 0x4
        pio_cur_addres = 0x1000

        for pioN in range(0, self.pio_num):
            size_macro = Macro(name=self.gen_Ith_pio_size_macro_name(pioN),
                               text="0x%X" % pio_def_size)
            address_macro = Macro(
                name=self.gen_Ith_pio_address_macro_name(pioN),
                text="0x%X" % pio_cur_addres)
            pio_cur_addres += pio_def_size

            self.header.add_types([size_macro, address_macro])

            self.pio_size_macros.append(size_macro)
            self.pio_address_macros.append(address_macro)

        if self.in_irq_num > 0:
            self.in_irq_macro = Macro(name="%s_IN_IRQ_NUM" %
                                      self.qtn.for_macros,
                                      text="%d" % self.in_irq_num)

            self.header.add_type(self.in_irq_macro)

        self.gen_property_macros(self.header)

        # TODO: current value of inherit_references is dictated by Qemu coding
        # policy. Hence, version API must be used there.
        header_source = self.header.generate(inherit_references=True)

        return header_source
Esempio n. 3
0
    def fill_header(self):
        self.state_struct = self.gen_state()

        self.header.add_type(self.state_struct)

        self.type_name_macros = Macro(name=self.qtn.type_macro,
                                      text='"%s"' % self.qtn.for_id_name)

        self.header.add_type(self.type_name_macros)

        self.type_cast_macro = Macro(
            name=self.qtn.for_macros,
            args=["obj"],
            text="OBJECT_CHECK({Struct}, (obj), {TYPE_MACRO})".format(
                TYPE_MACRO=self.qtn.type_macro, Struct=self.struct_name))

        self.header.add_type(self.type_cast_macro)

        line_origins(
            [self.type_name_macros, self.type_cast_macro, self.state_struct])

        for mmioN in range(0, self.mmio_num):
            size_macro = Macro(name=self.gen_Ith_mmio_size_macro_name(mmioN),
                               text=self.gen_mmio_size(
                                   self.mmio.get(mmioN, None)))
            name_macro = Macro(
                name=self.get_Ith_mmio_name_macro_name(mmioN),
                text='%s "_%s"' %
                (self.qtn.type_macro, self.get_Ith_mmio_id_component(mmioN)))

            (self.header if MACROS_2_HEADER else self.source).add_types(
                [size_macro, name_macro])

            self.mmio_size_macros.append(size_macro)
            self.mmio_name_macros.append(name_macro)

        pio_def_size = 0x4
        pio_cur_addres = 0x1000

        for pioN in range(0, self.pio_num):
            size_macro = Macro(name=self.gen_Ith_pio_size_macro_name(pioN),
                               text="0x%X" % pio_def_size)
            address_macro = Macro(
                name=self.gen_Ith_pio_address_macro_name(pioN),
                text="0x%X" % pio_cur_addres)
            pio_cur_addres += pio_def_size

            self.header.add_types([size_macro, address_macro])

            self.pio_size_macros.append(size_macro)
            self.pio_address_macros.append(address_macro)

        if self.in_irq_num > 0:
            self.in_irq_macro = Macro(name=self.qtn.for_macros + "_IN_IRQ_NUM",
                                      text="%d" % self.in_irq_num)

            self.header.add_type(self.in_irq_macro)

        self.gen_property_macros(self.header)
Esempio n. 4
0
File: qom.py Progetto: laerreal/qdt
    def char_gen_handlers(self, index, source, state_struct, type_cast_macro):
        ret = [
            self.char_gen_cb(proto_name, handler_name, index, source,
                             state_struct, type_cast_macro)
            for proto_name, handler_name in [(
                "IOCanReadHandler", self.char_can_read_name(index)
            ), ("IOReadHandler", self.char_read_name(index)
                ), ("IOEventHandler", self.char_event_name(index))]
        ]

        # Define handler relative order: can read, read, event
        line_origins(ret)

        return ret
Esempio n. 5
0
    def char_gen_handlers(self, index, source, state_struct, type_cast_macro):
        handlers = [("IOCanReadHandler", self.char_can_read_name(index), "0"),
                    ("IOReadHandler", self.char_read_name(index), None),
                    ("IOEventHandler", self.char_event_name(index), None)]
        if get_vp("char backend hotswap handler"):
            handlers.append((
                "BackendChangeHandler",
                self.char_backend_changed_name(index),
                "-1"  # hotswap is not supported by an empty device boilerplate
            ))

        ret = [
            self.char_gen_cb(proto_name, handler_name, index, source,
                             state_struct, type_cast_macro, handler_ret)
            for proto_name, handler_name, handler_ret in handlers
        ]

        # Define handler relative order: can read, read, event,
        # backend hotswap.
        line_origins(ret)

        return ret
Esempio n. 6
0
    def generate_header(self):
        self.state_struct = self.gen_state()
        self.header.add_type(self.state_struct)

        self.type_name_macros = Macro(name=self.qtn.type_macro,
                                      text='"%s"' % self.qtn.for_id_name)
        self.header.add_type(self.type_name_macros)

        self.type_cast_macro = Macro(
            name=self.qtn.for_macros,
            args=["obj"],
            text="OBJECT_CHECK({Struct}, (obj), {TYPE_MACRO})".format(
                TYPE_MACRO=self.qtn.type_macro, Struct=self.struct_name))
        self.header.add_type(self.type_cast_macro)

        line_origins(
            [self.type_name_macros, self.type_cast_macro, self.state_struct])

        self.vendor_macro = self.vendor.find_macro()

        if self.subsystem_vendor and self.subsystem:
            self.subsystem_vendor_macro = self.subsystem_vendor.find_macro()
        else:
            self.subsystem_vendor_macro = None

        try:
            self.device_macro = self.device.find_macro()
        except TypeNotRegistered:
            # TODO: add device id macro to pci_ids.h
            self.header.add_type(
                Macro(name="PCI_DEVICE_ID_%s_%s" %
                      (self.vendor.name, self.device.name),
                      text=self.device.id))

            self.device_macro = self.device.find_macro()

        if self.subsystem_vendor and self.subsystem:
            try:
                self.subsystem_macro = self.subsystem.find_macro()
            except TypeNotRegistered:
                # TODO: add device id macro to pci_ids.h
                self.header.add_type(
                    Macro(name="PCI_DEVICE_ID_%s_%s" %
                          (self.subsystem_vendor.name, self.subsystem.name),
                          text=self.subsystem.id))

                self.subsystem_macro = self.subsystem.find_macro()
        else:
            self.subsystem_macro = None

        self.pci_class_macro = self.pci_class.find_macro()

        mem_bar_def_size = 0x100

        for barN in range(0, self.mem_bar_num):
            size_macro = Macro(name=self.gen_Ith_mem_bar_size_macro_name(barN),
                               text="0x%X" % mem_bar_def_size)

            self.mem_bar_size_macros.append(size_macro)
            self.header.add_type(size_macro)

        if self.msi_messages_num > 0:
            self.msi_cap_offset = Macro(name="%s_MSI_CAP_OFFSET" %
                                        self.qtn.for_macros,
                                        text="0x48")
            self.msi_vectors = Macro(name="%s_MSI_VECTORS" %
                                     self.qtn.for_macros,
                                     text="%u" % self.msi_messages_num)
            self.msi_64bit = Macro(name="%s_MSI_64BIT" % self.qtn.for_macros,
                                   text="1")
            self.msi_masking = Macro(name="%s_MSI_VECTOR_MASKING" %
                                     self.qtn.for_macros,
                                     text="1")

            self.msi_types = [
                self.msi_cap_offset, self.msi_vectors, self.msi_64bit,
                self.msi_masking
            ]

            line_origins(self.msi_types)

            self.header.add_types(self.msi_types)

        self.gen_property_macros(self.header)

        # TODO: current value of inherit_references is dictated by Qemu coding
        # policy. Hence, version API must be used there.
        return self.header.generate(inherit_references=True)