This paper proposes a centralized decision making framework at the macro base station (MBS) for device to device (D2D) communication underlaying a two-tier cellular network. We consider a D2D pair in the presence of an MBS and a femto access point, each serving a user, with quality of service constraints for all users. Our proposed solution encompasses mode selection (choosing between cellular or reuse or dedicated mode), resource allocation (in cellular and dedicated mode) and power control (in reuse mode) within a single framework. The framework prioritizes D2D dedicated mode if the D2D pair are close to each other and orthogonal resources are available. Otherwise, it allows D2D reuse mode if the D2D satisfies both the maximum distance and an additional interference criteria. For reuse mode, we present a geometric vertex search approach to solve the power allocation problem. We analytically prove the validity of this approach and show that it achieves near optimal performance. For cellular and dedicated modes, we show that frequency sharing maximizes sum rate and solve the resource allocation problem in closed form. Our simulations demonstrate the advantages of the proposed framework in terms of the performance gains achieved in D2D mode.