免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 6556 | 回复: 3
打印 上一主题 下一主题

[内核入门] 对pci_set_dma_mask有点疑惑,求大神解答! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-12-04 16:10 |只看该作者 |倒序浏览
本帖最后由 yv9200 于 2014-12-04 16:13 编辑

在驱动里是这样调用的
struct pci_dev *pci_dev = NULL;
pci_set_dma_mask(pci_dev, DMA_BIT_MASK(32));

函数定义

int pci_set_dma_mask(struct pci_dev *dev, u64 mask)
{
        return dma_set_mask(&dev->dev, mask);
}

static inline int dma_set_mask(struct device *dev, u64 dma_mask)
{
        if (!dev->dma_mask || !dma_supported(dev, dma_mask))
                return -EIO;

        *dev->dma_mask = dma_mask;

        return 0;
}
结构体定义
struct pci_dev {
        struct list_head bus_list;        /* node in per-bus list */
        struct pci_bus        *bus;                /* bus this device is on */
        struct pci_bus        *subordinate;        /* bus this device bridges to */

        void                *sysdata;        /* hook for sys-specific extension */
        struct proc_dir_entry *procent;        /* device entry in /proc/bus/pci */
        struct pci_slot        *slot;                /* Physical slot this device is in */

        unsigned int        devfn;                /* encoded device & function index */
        unsigned short        vendor;
        unsigned short        device;
        unsigned short        subsystem_vendor;
        unsigned short        subsystem_device;
        unsigned int        class;                /* 3 bytes: (base,sub,prog-if) */
        u8                revision;        /* PCI revision, low byte of class word */
        u8                hdr_type;        /* PCI header type (`multi' flag masked out) */
        u8                pcie_cap;        /* PCI-E capability offset */
        u8                pcie_type;        /* PCI-E device/port type */
        u8                rom_base_reg;        /* which config register controls the ROM */
        u8                pin;                  /* which interrupt pin this device uses */

        struct pci_driver *driver;        /* which driver has allocated this device */
        u64                dma_mask;        /* Mask of the bits of bus address this
                                           device implements.  Normally this is
                                           0xffffffff.  You only need to change
                                           this if your device has broken DMA
                                           or supports 64-bit transfers.  */

        struct device_dma_parameters dma_parms;

        pci_power_t     current_state;  /* Current operating state. In ACPI-speak,
                                           this is D0-D3, D0 being fully functional,
                                           and D3 being off. */
        int                pm_cap;                /* PM capability offset in the
                                           configuration space */
        unsigned int        pme_support:5;        /* Bitmask of states from which PME#
                                           can be generated */
        unsigned int        pme_interrupt:1;
        unsigned int        d1_support:1;        /* Low power state D1 is supported */
        unsigned int        d2_support:1;        /* Low power state D2 is supported */
        unsigned int        no_d1d2:1;        /* Only allow D0 and D3 */
        unsigned int        mmio_always_on:1;        /* disallow turning off io/mem
                                                   decoding during bar sizing */
        unsigned int        wakeup_prepared:1;
        unsigned int        d3_delay;        /* D3->D0 transition time in ms */

#ifdef CONFIG_PCIEASPM
        struct pcie_link_state        *link_state;        /* ASPM link state. */
#endif

        pci_channel_state_t error_state;        /* current connectivity state */
        struct        device        dev;                /* Generic device interface */

        int                cfg_size;        /* Size of configuration space */

        /*
         * Instead of touching interrupt line and base address registers
         * directly, use the values stored here. They might be different!
         */
        unsigned int        irq;
        struct resource resource[DEVICE_COUNT_RESOURCE]; /* I/O and memory regions + expansion ROMs */
        resource_size_t        fw_addr[DEVICE_COUNT_RESOURCE]; /* FW-assigned addr */

        /* These fields are used by common fixups */
        unsigned int        transparent:1;        /* Transparent PCI bridge */
        unsigned int        multifunction:1;/* Part of multi-function device */
        /* keep track of device state */
        unsigned int        is_added:1;
        unsigned int        is_busmaster:1; /* device is busmaster */
        unsigned int        no_msi:1;        /* device may not use msi */
        unsigned int        block_ucfg_access:1;        /* userspace config space access is blocked */
        unsigned int        broken_parity_status:1;        /* Device generates false positive parity */
        unsigned int        irq_reroute_variant:2;        /* device needs IRQ rerouting variant */
        unsigned int         msi_enabled:1;
        unsigned int        msix_enabled:1;
        unsigned int        ari_enabled:1;        /* ARI forwarding */
        unsigned int        is_managed:1;
        unsigned int        is_pcie:1;        /* Obsolete. Will be removed.
                                           Use pci_is_pcie() instead */
        unsigned int    needs_freset:1; /* Dev requires fundamental reset */
        unsigned int        state_saved:1;
        unsigned int        is_physfn:1;
        unsigned int        is_virtfn:1;
        unsigned int        reset_fn:1;
        unsigned int    is_hotplug_bridge:1;
        unsigned int    __aer_firmware_first_valid:1;
        unsigned int        __aer_firmware_first:1;
        pci_dev_flags_t dev_flags;
        atomic_t        enable_cnt;        /* pci_enable_device has been called */

        u32                saved_config_space[16]; /* config space saved at suspend time */
        struct hlist_head saved_cap_space;
        struct bin_attribute *rom_attr; /* attribute descriptor for sysfs ROM entry */
        int rom_attr_enabled;                /* has display of the rom attribute been enabled? */
        struct bin_attribute *res_attr[DEVICE_COUNT_RESOURCE]; /* sysfs file for resources */
        struct bin_attribute *res_attr_wc[DEVICE_COUNT_RESOURCE]; /* sysfs file for WC mapping of resources */
#ifdef CONFIG_PCI_MSI
        struct list_head msi_list;
#endif
        struct pci_vpd *vpd;
#ifdef CONFIG_PCI_IOV
        union {
                struct pci_sriov *sriov;        /* SR-IOV capability related */
                struct pci_dev *physfn;        /* the PF this VF is associated with */
        };
        struct pci_ats        *ats;        /* Address Translation Service */
#endif
};


struct device {
        struct device                *parent;

        struct device_private        *p;

        struct kobject kobj;
        const char                *init_name; /* initial name of the device */
        struct device_type        *type;

        struct mutex                mutex;        /* mutex to synchronize calls to
                                         * its driver.
                                         */

        struct bus_type        *bus;                /* type of bus device is on */
        struct device_driver *driver;        /* which driver has allocated this
                                           device */
        void                *platform_data;        /* Platform specific data, device
                                           core doesn't touch it */
        struct dev_pm_info        power;

#ifdef CONFIG_NUMA
        int                numa_node;        /* NUMA node this device is close to */
#endif
        u64                *dma_mask;        /* dma mask (if dma'able device) */
        u64                coherent_dma_mask;/* Like dma_mask, but for
                                             alloc_coherent mappings as
                                             not all hardware supports
                                             64 bit addresses for consistent
                                             allocations such descriptors. */

        struct device_dma_parameters *dma_parms;

        struct list_head        dma_pools;        /* dma pools (if dma'ble) */

        struct dma_coherent_mem        *dma_mem; /* internal for coherent mem
                                             override */
        /* arch specific additions */
        struct dev_archdata        archdata;
#ifdef CONFIG_OF
        struct device_node        *of_node;
#endif

        dev_t                        devt;        /* dev_t, creates the sysfs "dev" */

        spinlock_t                devres_lock;
        struct list_head        devres_head;

        struct klist_node        knode_class;
        struct class                *class;
        const struct attribute_group **groups;        /* optional groups */

        void        (*release)(struct device *dev);
};
我的c语言功底不是很好,大神们有时间帮我看看指针那块调用是否有错误。谢谢!!!!!!

论坛徽章:
9
辰龙
日期:2014-08-18 20:38:42未羊
日期:2014-09-04 08:50:45丑牛
日期:2014-09-06 00:12:55寅虎
日期:2014-12-22 20:50:56摩羯座
日期:2015-01-14 22:28:15巳蛇
日期:2015-01-23 20:39:272015年辞旧岁徽章
日期:2015-03-03 16:54:1515-16赛季CBA联赛之青岛
日期:2016-03-13 23:37:1915-16赛季CBA联赛之深圳
日期:2016-03-29 18:52:38
2 [报告]
发表于 2014-12-04 23:06 |只看该作者
建议你先把C语言学好,再来碰内核,不然会死得很惨。
建议你先把Linux应用程序编程学好。
你只定义了pci_dev指针,都没有定义pci_dev变量,你怎么去赋值?
你应该先定义一个变量,再去取指针。

论坛徽章:
0
3 [报告]
发表于 2014-12-05 12:14 |只看该作者
多谢大神建议,但目前领导就让我做这块,没办法,只能找时间多学C语言了
k297499226 该用户已被删除
4 [报告]
发表于 2015-04-11 14:48 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP