mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-09 11:16:47 +00:00
增加了xhci cap regs的数据结构
This commit is contained in:
parent
6f5d73771f
commit
6ecc19cc48
@ -3,6 +3,9 @@
|
||||
#include <common/kprint.h>
|
||||
#include <driver/pci/pci.h>
|
||||
#include <debug/bug.h>
|
||||
#include <process/spinlock.h>
|
||||
|
||||
extern spinlock_t xhci_controller_init_lock; // xhci控制器初始化锁
|
||||
|
||||
#define MAX_USB_NUM 8 // pci总线上的usb设备的最大数量
|
||||
|
||||
@ -17,6 +20,8 @@ static int usb_pdevs_count = 0;
|
||||
void usb_init()
|
||||
{
|
||||
kinfo("Initializing usb driver...");
|
||||
spin_init(&xhci_controller_init_lock);
|
||||
|
||||
// 获取所有usb-pci设备的列表
|
||||
pci_get_device_structure(USB_CLASS, USB_SUBCLASS, usb_pdevs, &usb_pdevs_count);
|
||||
|
||||
@ -41,7 +46,7 @@ void usb_init()
|
||||
|
||||
case USB_TYPE_XHCI:
|
||||
// 初始化对应的xhci控制器
|
||||
xhci_init(usb_pdevs[i]);
|
||||
xhci_init((struct pci_device_structure_general_device_t *)usb_pdevs[i]);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -1,11 +1,28 @@
|
||||
#include "xhci.h"
|
||||
#include <common/kprint.h>
|
||||
#include <debug/bug.h>
|
||||
#include <process/spinlock.h>
|
||||
|
||||
spinlock_t xhci_controller_init_lock; // xhci控制器初始化锁(在usb_init中被初始化)
|
||||
|
||||
static int xhci_ctrl_count = 0; // xhci控制器计数
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief 初始化xhci控制器
|
||||
*
|
||||
* @param header 指定控制器的pci device头部
|
||||
*/
|
||||
void xhci_init(struct pci_device_structure_header_t *header)
|
||||
void xhci_init(struct pci_device_structure_general_device_t *dev_hdr)
|
||||
{
|
||||
spin_lock(&xhci_controller_init_lock);
|
||||
kinfo("Initializing xhci host controller: bus=%#02x, device=%#02x, func=%#02x, VendorID=%#04x, irq_line=%d, irq_pin=%d", dev_hdr->header.bus, dev_hdr->header.device, dev_hdr->header.func, dev_hdr->header.Vendor_ID, dev_hdr->Interrupt_Line, dev_hdr->Interrupt_PIN );
|
||||
|
||||
pci_write_config(dev_hdr->header.bus, dev_hdr->header.device, dev_hdr->header.func, 0x4, 0x0006); // mem I/O access enable and bus master enable
|
||||
|
||||
|
||||
|
||||
++xhci_ctrl_count;
|
||||
spin_unlock(&xhci_controller_init_lock);
|
||||
}
|
@ -1,9 +1,52 @@
|
||||
#pragma once
|
||||
#include <driver/usb/usb.h>
|
||||
#include <driver/pci/pci.h>
|
||||
|
||||
// xhci Capability Registers offset
|
||||
#define XHCI_CAPS_CAPLENGTH 0x00 // Cap 寄存器组的长度
|
||||
#define XHCI_CAPS_RESERVED 0x01
|
||||
#define XHCI_CAPS_HCIVERSION 0x02 // 接口版本号
|
||||
#define XHCI_CAPS_HCSPARAMS1 0x04
|
||||
#define XHCI_CAPS_HCSPARAMS2 0x08
|
||||
#define XHCI_CAPS_HCSPARAMS3 0x0c
|
||||
#define XHCI_CAPS_HCCPARAMS1 0x10 // capability params 1
|
||||
#define XHCI_CAPS_DBOFF 0x14 // Doorbell offset
|
||||
#define XHCI_CAPS_RTSOFF 0x18 // Runtime register space offset
|
||||
#define XHCI_CAPS_HCCPARAMS2 0x1c // capability params 2
|
||||
|
||||
|
||||
struct xhci_caps_HCSPARAMS1_reg_t
|
||||
{
|
||||
unsigned max_slots : 8; // 最大插槽数
|
||||
unsigned max_intrs : 11; // 最大中断数
|
||||
unsigned reserved : 5;
|
||||
unsigned max_ports : 8; // 最大端口数
|
||||
}__attribute__((packed));
|
||||
|
||||
|
||||
/**
|
||||
* @brief xhci端口信息
|
||||
*
|
||||
*/
|
||||
struct xhci_port_info_t
|
||||
{
|
||||
uint8_t flags; // port flags
|
||||
uint8_t paired_port_num; // 与当前端口所配对的另一个端口(相同物理接口的不同速度的port)
|
||||
uint8_t offset; // offset of this port within this protocal
|
||||
uint8_t reserved;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct xhci_controller_t
|
||||
{
|
||||
struct pci_device_structure_general_device_t *pci_dev_hdr; // 指向pci header结构体的指针
|
||||
int controller_id; // 操作系统给controller的编号
|
||||
int vbase; // 虚拟地址base(bar0映射到的虚拟地址)
|
||||
struct xhci_port_info_t *ports; // 指向端口信息数组的指针
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief 初始化xhci控制器
|
||||
*
|
||||
* @param header 指定控制器的pci device头部
|
||||
*/
|
||||
void xhci_init(struct pci_device_structure_header_t *header);
|
||||
void xhci_init(struct pci_device_structure_general_device_t *header);
|
@ -44,6 +44,7 @@
|
||||
#define IO_APIC_MAPPING_OFFSET 0xfec00000UL
|
||||
#define LOCAL_APIC_MAPPING_OFFSET 0xfee00000UL
|
||||
#define AHCI_MAPPING_OFFSET 0xff200000UL // AHCI 映射偏移量,之后使用了4M的地址
|
||||
#define XHCI_MAPPING_OFFSET 0x100000000 // XHCI控制器映射偏移量(后方请预留1GB的虚拟空间来映射不同的controller)
|
||||
|
||||
// ===== 内存区域属性 =====
|
||||
// DMA区域
|
||||
|
Loading…
x
Reference in New Issue
Block a user