1
0
Fork 0
mirror of https://github.com/hermitcore/libhermit.git synced 2025-03-09 00:00:03 +01:00

add option to enable the bus mastering mode for a device

- enable this option for all NICs
This commit is contained in:
Stefan Lankes 2016-08-21 14:58:31 +02:00
parent ced8bc2cc9
commit a827b859a7
4 changed files with 22 additions and 8 deletions

View file

@ -57,12 +57,13 @@ int pci_init(void);
* @param vendor_id The device's vendor ID
* @param device_id the device's ID
* @param info Pointer to the record pci_info_t where among other the IObase address will be stored
* @param enable_bus_master If true, the bus mastering will be enabled.
*
* @return
* - 0 on success
* - -EINVAL (-22) on failure
*/
int pci_get_device_info(uint32_t vendor_id, uint32_t device_id, pci_info_t* info);
int pci_get_device_info(uint32_t vendor_id, uint32_t device_id, pci_info_t* info, int8_t enble_bus_master);
/** @brief Print information of existing pci adapters
*

View file

@ -110,6 +110,14 @@ static inline uint32_t pci_what_iobase(uint32_t bus, uint32_t slot, uint32_t nr)
return pci_conf_read(bus, slot, PCI_CBIO + nr*4) & 0xFFFFFFFC;
}
static inline void pci_bus_master(uint32_t bus, uint32_t slot)
{
// set the device to a bus master
uint32_t cmd = pci_conf_read(bus, slot, PCI_CFCS) | 0x4;
pci_conf_write(bus, slot, PCI_CFCS, cmd);
}
static inline uint32_t pci_what_size(uint32_t bus, uint32_t slot, uint32_t nr)
{
uint32_t tmp, ret;
@ -138,7 +146,7 @@ int pci_init(void)
return 0;
}
int pci_get_device_info(uint32_t vendor_id, uint32_t device_id, pci_info_t* info)
int pci_get_device_info(uint32_t vendor_id, uint32_t device_id, pci_info_t* info, int8_t bus_master)
{
uint32_t slot, bus, i;
@ -155,9 +163,11 @@ int pci_get_device_info(uint32_t vendor_id, uint32_t device_id, pci_info_t* info
(((adapters[bus][slot] & 0xffff0000) >> 16) == device_id)) {
for(i=0; i<6; i++) {
info->base[i] = pci_what_iobase(bus, slot, i);
info->size[i] = (info->base[i]) ? pci_what_size(bus, slot, i) : 0;
info->size[i] = (info->base[i]) ? pci_what_size(bus, slot, i) : 0;
}
info->irq = pci_what_irq(bus, slot);
if (bus_master)
pci_bus_master(bus, slot);
return 0;
}
}

View file

@ -335,7 +335,7 @@ err_t e1000if_init(struct netif* netif)
tmp8 = 0;
while (board_tbl[tmp8].vendor_str) {
if (pci_get_device_info(board_tbl[tmp8].vendor, board_tbl[tmp8].device, &pci_info) == 0)
if (pci_get_device_info(board_tbl[tmp8].vendor, board_tbl[tmp8].device, &pci_info, 1) == 0)
break;
tmp8++;
}

View file

@ -304,7 +304,7 @@ err_t rtl8139if_init(struct netif* netif)
tmp8 = 0;
while (board_tbl[tmp8].vendor_str) {
if (pci_get_device_info(board_tbl[tmp8].vendor, board_tbl[tmp8].device, &pci_info) == 0)
if (pci_get_device_info(board_tbl[tmp8].vendor, board_tbl[tmp8].device, &pci_info, 1) == 0)
break;
tmp8++;
}
@ -312,6 +312,8 @@ err_t rtl8139if_init(struct netif* netif)
if (!board_tbl[tmp8].vendor_str)
return ERR_ARG;
//kprintf("Found %s %s\n", board_tbl[tmp8].vendor_str, board_tbl[tmp8].device_str);
rtl8139if = kmalloc(sizeof(rtl1839if_t));
if (!rtl8139if) {
LWIP_DEBUGF(NETIF_DEBUG, ("rtl8139if_init: out of memory\n"));
@ -340,9 +342,9 @@ err_t rtl8139if_init(struct netif* netif)
return ERR_MEM;
}
memset(rtl8139if->tx_buffer[0], 0x00, 4*TX_BUF_LEN);
rtl8139if->tx_buffer[1] = rtl8139if->tx_buffer[0] + TX_BUF_LEN;
rtl8139if->tx_buffer[2] = rtl8139if->tx_buffer[1] + TX_BUF_LEN;
rtl8139if->tx_buffer[3] = rtl8139if->tx_buffer[2] + TX_BUF_LEN;
rtl8139if->tx_buffer[1] = rtl8139if->tx_buffer[0] + 1*TX_BUF_LEN;
rtl8139if->tx_buffer[2] = rtl8139if->tx_buffer[0] + 2*TX_BUF_LEN;
rtl8139if->tx_buffer[3] = rtl8139if->tx_buffer[0] + 3*TX_BUF_LEN;
netif->state = rtl8139if;
mynetif = netif;
@ -480,5 +482,6 @@ err_t rtl8139if_init(struct netif* netif)
/* broadcast capability */
netif->flags |= NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_IGMP;
vma_dump();
return ERR_OK;
}