void* osl_malloc(osl_t *osh, uint size) { void *addr; if (osh) ASSERT(osh->magic == OS_HANDLE_MAGIC); #ifdef DHD_USE_STATIC_BUF if (bcm_static_buf) { int i = 0; if ((size >= PAGE_SIZE)&&(size <= STATIC_BUF_SIZE)) { down(&bcm_static_buf->static_sem); for (i = 0; i < MAX_STATIC_BUF_NUM; i++) { if (bcm_static_buf->buf_use[i] == 0) break; } if (i == MAX_STATIC_BUF_NUM) { up(&bcm_static_buf->static_sem); OSL_MSG_INFO(("osl_malloc: all static buff in use!\n")); goto original; } bcm_static_buf->buf_use[i] = 1; up(&bcm_static_buf->static_sem); bzero(bcm_static_buf->buf_ptr+STATIC_BUF_SIZE*i, size); if (osh) osh->malloced += size; return ((void *)(bcm_static_buf->buf_ptr+STATIC_BUF_SIZE*i)); } } original: #endif if ((addr = kmalloc(size, GFP_ATOMIC)) == NULL) { OSL_MSG_ERROR(("osl_malloc: GFP_ATOMIC failed, trying GFP_KERNEL\n")); if ((addr = kmalloc(size, GFP_KERNEL)) == NULL) { OSL_MSG_ERROR(("osl_malloc: GFP_KERNEL failed also\n")); if (osh) osh->failed++; return (NULL); } } if (osh) osh->malloced += size; return (addr); }
osl_t * osl_attach(void *pdev, uint bustype, bool pkttag) { osl_t *osh; osh = kmalloc(sizeof(osl_t), GFP_ATOMIC); ASSERT(osh); bzero(osh, sizeof(osl_t)); ASSERT(ABS(BCME_LAST) == (ARRAYSIZE(linuxbcmerrormap) - 1)); osh->magic = OS_HANDLE_MAGIC; osh->malloced = 0; osh->failed = 0; osh->dbgmem_list = NULL; osh->pdev = pdev; osh->pub.pkttag = pkttag; osh->bustype = bustype; switch (bustype) { case PCI_BUS: case SI_BUS: case PCMCIA_BUS: osh->pub.mmbus = TRUE; break; case JTAG_BUS: case SDIO_BUS: case USB_BUS: case SPI_BUS: osh->pub.mmbus = FALSE; break; default: ASSERT(FALSE); break; } #ifdef DHD_USE_STATIC_BUF if (!bcm_static_buf) { if (!(bcm_static_buf = (bcm_static_buf_t *)dhd_os_prealloc(3, STATIC_BUF_SIZE+ STATIC_BUF_TOTAL_LEN))) { OSL_MSG_ERROR(("osl_attach: can not alloc static buf!\n")); } else OSL_MSG_INFO(("osl_attach: alloc static buf at %x!\n", (unsigned int)bcm_static_buf)); init_MUTEX(&bcm_static_buf->static_sem); bcm_static_buf->buf_ptr = (unsigned char *)bcm_static_buf + STATIC_BUF_SIZE; } if (!bcm_static_skb) { int i; #ifndef CUSTOMER_HW_SAMSUNG void *skb_buff_ptr = 0; #endif bcm_static_skb = (bcm_static_pkt_t *)((char *)bcm_static_buf + 2048); #ifdef CUSTOMER_HW_SAMSUNG for (i = 0; i < MAX_STATIC_PKT_NUM; i++) { bcm_static_skb->skb_4k[i] = dev_alloc_skb(DHD_SKB_1PAGE_BUFSIZE); if (bcm_static_skb->skb_4k[i] == NULL) { OSL_MSG_ERROR(("osl_attach: 4K memory allocation failure. idx=%d\n", i)); goto err; } } for (i = 0; i < MAX_STATIC_PKT_NUM; i++) { bcm_static_skb->skb_8k[i] = dev_alloc_skb_kernel(DHD_SKB_2PAGE_BUFSIZE); if (bcm_static_skb->skb_8k[i] == NULL) { OSL_MSG_ERROR(("osl_attach: 8K memory allocation failure. idx=%d\n", i)); goto err; } } bcm_static_skb->skb_16k = dev_alloc_skb_kernel(DHD_SKB_4PAGE_BUFSIZE); if (bcm_static_skb->skb_16k == NULL) { OSL_MSG_ERROR(("osl_attach: 16K memory allocation failure. idx=%d\n", i)); goto err; } #else skb_buff_ptr = dhd_os_prealloc(4, 0); bcopy(skb_buff_ptr, bcm_static_skb, sizeof(struct sk_buff *)*16); #endif /* CUSTOMER_HW_SAMSUNG */ for (i = 0; i < MAX_STATIC_PKT_NUM*2+1; i++) bcm_static_skb->pkt_use[i] = 0; init_MUTEX(&bcm_static_skb->osl_pkt_sem); } #endif return osh; err: kfree(osh); return 0; }
osl_t * osl_attach(void *pdev, uint bustype, bool pkttag) { osl_t *osh; osh = kmalloc(sizeof(osl_t), GFP_ATOMIC); ASSERT(osh); bzero(osh, sizeof(osl_t)); /* Check that error map has the right number of entries in it */ ASSERT(ABS(BCME_LAST) == (ARRAYSIZE(linuxbcmerrormap) - 1)); osh->magic = OS_HANDLE_MAGIC; atomic_set(&osh->malloced, 0); osh->failed = 0; osh->dbgmem_list = NULL; osh->pdev = pdev; osh->pub.pkttag = pkttag; osh->bustype = bustype; switch (bustype) { case PCI_BUS: case SI_BUS: case PCMCIA_BUS: osh->pub.mmbus = TRUE; break; case JTAG_BUS: case SDIO_BUS: case USB_BUS: case SPI_BUS: case RPC_BUS: osh->pub.mmbus = FALSE; break; default: ASSERT(FALSE); break; } #ifdef DHD_USE_STATIC_BUF if (!bcm_static_buf) { if (!(bcm_static_buf = (bcm_static_buf_t *)dhd_os_prealloc(3, STATIC_BUF_SIZE+ STATIC_BUF_TOTAL_LEN))) { OSL_MSG_ERROR(("can not alloc static buf!\n")); } else OSL_MSG_INFO(("alloc static buf at %x!\n", (unsigned int)bcm_static_buf)); init_MUTEX(&bcm_static_buf->static_sem); bcm_static_buf->buf_ptr = (unsigned char *)bcm_static_buf + STATIC_BUF_SIZE; } if (!bcm_static_skb) { int i; void *skb_buff_ptr = 0; bcm_static_skb = (bcm_static_pkt_t *)((char *)bcm_static_buf + 2048); skb_buff_ptr = dhd_os_prealloc(4, 0); bcopy(skb_buff_ptr, bcm_static_skb, sizeof(struct sk_buff *)*(MAX_STATIC_PKT_NUM*2+1)); for (i = 0; i < MAX_STATIC_PKT_NUM*2+1; i++) bcm_static_skb->pkt_use[i] = 0; init_MUTEX(&bcm_static_skb->osl_pkt_sem); } #endif /* DHD_USE_STATIC_BUF */ return osh; }